Disable Back Button In Browser Using JavaScript

In this article, we will learn how to disable the back button in the browser using JavaScript.

Open the index.html file and add the code in it.

<!DOCTYPE html>
<html>
<head>
    <script>
        history.pushState(null, null, location.href);
        window.onpopstate = function () {
            history.go(1);
        };
    </script>
</head>
<body>
    Welcome
</body>
</html>

That’s it.

Output:

Also, check Detect Inactivity In Browser Using JavaScript

2 Comments

  1. avotra

    thank you bro, you save my day

    0
    0
    Reply
    1. You’re welcome 🙂

      0
      0
      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories