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

206
Views
prevent user from clicking browser's back button

I want to disable the browser's back button. I have tried some javascript codes to implement the same. But those codes didn't meet my requirements. It works in firefox but not working in chrome and edge. Sometimes it works all the three but randomly working and not working.

Can anybody share me the script disable the back button in all browsers without flaws like random behaviour.

Here I showed some scripts I have tried

history.pushState(null, null, window.location.href);
history.back();
window.onpopstate = () => history.forward();

history.pushState(null, null, location.href);
history.back();
history.forward();
window.onpopstate = function () { history.go(1); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can refer to the following code. I test the code sample in Edge, Chrome and Firefox, it works well.

Save this file as a.html for the first page:

<!DOCTYPE html>
<html>
<head>
    <title>First Page</title>
    <script type="text/javascript">
        function preventBack() {
            window.history.forward();
        }
        setTimeout("preventBack()", 0);
        window.onunload = function () { null };
    </script>
</head>
<body>
    <h3>This is first page</h3>
    <a href="b.html">Goto second Page</a>
</body>
</html>

Save this file as b.html for the second page:

<!DOCTYPE html>
<html>
<head>
    <title>
        Blocking Back Button using javascript
    </title>
</head>
<body>
    <h3>This is second page</h3>
    <p>
        On this page, back button functionality is disabled.
    </p>
</body>
</html>

Run a.html and click to navigate to b.html. Then click browser's back button on b.html, it won't navigate to a.html.

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!