Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
disabled browser back button google chrome and edge
window.history.pushState(null, null, location.href);

window.addEventListener('popstate', () => {
    history.go(1);
    alert('Back button is not allowed.');
});

Show message when browser back button clicked on chrome and edge latest version above code snippet is not working.

On Firefox it works perfectly.

Please suggest any workaround.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try running this code and then use browser back button.

<script>
  (function (global) {
    if (typeof global === "undefined") {
      throw new Error("window is undefined");
    }

    var _hash = "!";
    var noBackPlease = function () {
      global.location.href += "#";

      // making sure we have the fruit available for juice....
      // 50 milliseconds for just once do not cost much (^__^)
      global.setTimeout(function () {
        global.location.href += "!";
      }, 50);
    };

    // Earlier we had setInerval here....
    global.onhashchange = function () {
      if (global.location.hash !== _hash) {
        global.location.hash = _hash;
      }
    };

    global.onload = function () {
      noBackPlease();

      // disables backspace on page except on input fields and textarea..
      document.body.onkeydown = function (e) {
        var elm = e.target.nodeName.toLowerCase();
        if (e.which === 8 && elm !== "input" && elm !== "textarea") {
          e.preventDefault();
        }
        // stopping event bubbling up the DOM tree..
        e.stopPropagation();
      };
    };
  })(window);
</script>
<script src="http://static.jsbin.com/js/render/edit.js?4.1.8"></script>
<script>
  jsbinShowEdit &&
    jsbinShowEdit({
      static: "http://static.jsbin.com",
      root: "http://jsbin.com",
    });
</script>
<script>
  (function (i, s, o, g, r, a, m) {
    i["GoogleAnalyticsObject"] = r;
    (i[r] =
      i[r] ||
      function () {
        (i[r].q = i[r].q || []).push(arguments);
      }),
      (i[r].l = 1 * new Date());
    (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
    a.async = 1;
    a.src = g;
    m.parentNode.insertBefore(a, m);
  })(
    window,
    document,
    "script",
    "https://www.google-analytics.com/analytics.js",
    "ga"
  );

  ga("create", "UA-1656750-34", "auto");
  ga("require", "linkid", "linkid.js");
  ga("require", "displayfeatures");
  ga("send", "pageview");
</script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!