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.

How to disable back button in browser using javascript

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">
window.history.forward();
function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<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.