Share on Google+Share on Google+

How to disable back button in browser using javascript

Here is the javascript code that will help you disable back button in your web browser.

There are times while developing a website, we need to disable back button in browser. Most common example of this is found in Online Banking Websites.

Most of the time the back button is disabled because a user can hit back and navigate from the page and forget to logout.

Given below code in Java script that will disable the working of Back button in Browser:

<SCRIPT type="text/javascript">
function noBack() { window.history.forward(); }
<BODY onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">

Note: If you want to stop user navigating back from Page 2 to Page 1 then the code here is placed in the head section of Page 1.


Posted on: October 2, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: How to disable back button in browser using javascript  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image