How to Disable the browsers’ back button

You can Disable the browsers’ back button if you want to prevent your users to go back for some reasons like the registration page or for some pages once they are submitted should not be reversed back, which might lead into unwanted problems .

There is a little hack to achieve this, you can use the following js code.


19 Replies to “How to Disable the browsers’ back button”

  1. You include this inside javascript tags and call it on page load
    In the body tag of your page
    add this
    onload=”javascript: location.replace(yourURL)window.history.forward(1);”

    Else You can put this code at the end of the page
    like this


  2. Awesome!!! Much better than just expiring the page!

    This is what I typically use in ASP.NET
    Response.ExpiresAbsolute = Convert.ToDateTime(“01-01-1901”);
    Response.Expires = 0;
    Response.CacheControl = “no-cache”;

    Just running window.history.forward(1); on body onload event does the trick. Great, Great idea!!!!

  3. It works but i want to know tat wat shud be the modified version of d above code if i dont want to replace any URL n want my page whose back button is 2 b disabled to be the same page after pressing back button? i dont want to go to ne other page but be in da same page.

  4. location.replace(yourURL)

    hi the above code is noy working in my jsp . what is the problem tell me anyone . i have written like this in my body tag

  5. Admiring the persistence you put into your blog and detailed information you present.

    It’s good to come across a blog every once in a while that isn’t the same outdated rehashed information.
    Wonderful read! I’ve saved your site and I’m including your RSS feeds to my Google

Leave a Reply to Newbie Cancel reply

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