Jun 26, 2019

Disable back button on browser

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...
Locked
This question is locked and replying has been disabled.
Community content may not be verified or up-to-date. Learn more.
All Replies (20)
Jul 23, 2019
I have the same problem could find any solution? i need help :(
Last edited Jul 24, 2019
Sep 12, 2019
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?
Google user
Oct 12, 2019
Same problem. The Android and IOS Chrome version >= 75 hava the problem.
Oct 22, 2019

I am also facing the same problem in windows, android and IOS chrome version (Above 75 v)
Oct 28, 2019
Any solution for this? 

I am not able to handle the browser back button if I not clicking anywhere in the body.

Is there any alternate solution for this?
Nov 13, 2019
So far i check,those problem regarding onpopstate still there  and its only trigger when click on page or you add any javascript source code on developer tools > Console Tab  like console.log('test");. If there any solution for this, please provide it.
Nov 13, 2019
Y'all are all fucked
Nov 19, 2019
Is there any updates on this?
Do we have any listners for chrome to handle this ?
Is it wise to manipulate the browser history state.....since that is looking quite complex ??
Nov 22, 2019
<script type="text/javascript">
        window.history.forward();
        function noBack() {
            window.history.forward();
        }
    </script

Its working fine for the chrome, need to add this in previous page for which back button actually redirects to.
Nov 28, 2019
Can someone provide a solution to disable chrome browser back button in latest version?
Nov 28, 2019
The below snippet also not working in latest chrome version 78.0.39. Other browsers are seems to be working. There may be a some blockage in the latest upgrade. 

<script type="text/javascript">
        window.history.forward();
        function noBack() {
            window.history.forward();
        }
    </script>
Dec 5, 2019
I'm also waiting for a solution for this.or is there any vuejs specific solution for this..without using these native methods.
Jan 14, 2020
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.
false
1435107696809329007
true
Search Help Center
true
true
true
true
true
237
false
Search
Clear search
Close search
Main menu