/chrome/community?hl=en
This content is likely not relevant anymore. Try searching or browse recent questions.
Disable back button on browser
0
I would like to disable browser back button... I am trying with below code...

<script type="text/javascript">
history.pushState(null, document.title, location.href);

window.addEventListener('popstate', function (event)
{
  history.pushState(null, document.title, location.href);
 
  
});
</script>


But it is working on firefox ...but not on chrome...

Is it possible to provide pointers or possible solution if at all....

Is it feasible...
Latest Update Latest Updates (0)
Relevant Answer Relevant Answers (0)
All Replies (20)
Relevant Answer
I have the same problem could find any solution? i need help :(
marked this as an answer
Relevant Answer
The above code is not working until we click on anywhere on window. Without clicking anywhere on window then if i click on back button then it is going back. (on Chrome 75)
Any one has solution.
marked this as an answer
Relevant Answer
I am also able to confirm that this issue has only started happening since 75 was installed.
The user must click somewhere within the render window to allow the back button to raise the popstate event.
marked this as an answer
Relevant Answer
I don't know but it may be that Chrome is trying to stop this happening.
After all it could be the desired behaviour of a malicious or advertising website so you can't go back and stop looking at it.
marked this as an answer
Relevant Answer
Did anyone find a solution for this? I tried code a manual click on the body of the html but still doesn't work.
marked this as an answer
Relevant Answer
Same problem here. Could not make it working unless the user clicks in any area within web page.
marked this as an answer
Relevant Answer
I have the same problem. Did anyone find a solution?
marked this as an answer
Relevant Answer
So please they make that optional with user prompt (like camera/mic/...), because for some PWA’s this is very important to block physical back button (accidentally pressed)!
marked this as an answer
Relevant Answer
I have the same problem. Discovered that this function works if you inspect the code in chrome. 
Any solution to this problem yet? Do you know when this issue will be solved?
marked this as an answer
Relevant Answer
I found solution for this problem which is manage to block the back button history browser:
<script type = "text/javascript" > history.pushState(null, null, location.href); history.back(); history.forward(); window.onpopstate = function () { history.go(1); }; </script>
The problem with Chrome is that it doesn't trigger onpopstate event unless you make browser action ( i.e. call history.back). Thats why I've added those to script. After adding only that made it work in Chrome but other browsers stopped adding history.forward fixed it and started to work on every browser mentioned.
Hope it helps.
marked this as an answer
This question is locked and replying has been disabled.
Discard post? You will lose what you have written so far.
Write a reply
10 characters required
Failed to attach file, click here to try again.
Discard post?
You will lose what you have written so far.
Personal information found

We found the following personal information in your message:

This information will be visible to anyone who visits or subscribes to notifications for this post. Are you sure you want to continue?

A problem occurred. Please try again.
Create Reply
Edit Reply
This will remove the reply from the Answers section.
Notifications are off
Your notifications are currently off and you won't receive subscription updates. To turn them on, go to Notifications preferences on your Profile page.
Report abuse
Google takes abuse of its services very seriously. We're committed to dealing with such abuse according to the laws in your country of residence. When you submit a report, we'll investigate it and take the appropriate action. We'll get back to you only if we require additional details or have more information to share.

Go to the Legal Help page to request content changes for legal reasons.

Reported post for abuse
Unable to send report.
Report post
What type of post are you reporting?
Google takes abuse of its services very seriously. We're committed to dealing with such abuse according to the laws in your country of residence. When you submit a report, we'll investigate it and take the appropriate action. We'll get back to you only if we require additional details or have more information to share.

Go to the Legal Help page to request content changes for legal reasons.

Reported post for abuse
Unable to send report.
This reply is no longer available.
/chrome/threads
//accounts.google.com/ServiceLogin
You'll receive email notifications for new posts at
Unable to delete question.
Unable to update vote.
Unable to update subscription.
You have been unsubscribed
Deleted
Unable to delete reply.
Removed from Answers
Removed from Updates
Marked as Recommended Answer
Marked as Update
Removed recommendation
Undo
Unable to update reply.
Unable to update vote.
Thank you. Your response was recorded.
Unable to undo vote.
Thank you. This reply will now display in the answers section.
Link copied
Locked
Unlocked
Unable to lock
Unable to unlock
Pinned
Unpinned
Unable to pin
Unable to unpin
Marked
Unmarked
Unable to mark
Reported as off topic
Known Issue
Fixed
Marked Fixed
Unmarked Fixed
Unable to mark fixed
Unable to unmark fixed
/profile/0
false
Search
Clear search
Close search
Google apps
Main menu
Search Help Center
true
237
false