0

I want to disable back button in the navigator with javascript, i used:

 document.addEventListener("popstate", urlBackButton, false);

    function urlBackButton() {
       isBackButton = true;
        var url = $("#cannotUseBack").val();
        if (url == "/mypage") {
            window.history.go(1);
            return false;
        } else {
            return true;
        }
    }

It doesn't work.

Any help is appreciated. Thanks!

nircraft
  • 8,242
  • 5
  • 30
  • 46
  • Does this answer your question? [how to stop browser back button using javascript](https://stackoverflow.com/questions/12381563/how-to-stop-browser-back-button-using-javascript) – B. Go Dec 16 '19 at 22:24

1 Answers1

0

You can try the below code, it is working in chrome.

history.pushState(null, null, location.href);
window.onpopstate = function () {
    history.go(1);
};
KAMAL1910
  • 5
  • 2