Disable Back Button in Browser

Technically it is not possible to disable the back button, however there are certain things you can do to work with the back button actions.

window.history.forward();    function noBack() { window.history.forward(); }
window.onbeforeunload = function() { return "Please DO NOT USE the browser back button."; };

This works great in IE and Chrome but not in other browsers.

You can also try:-

<SCRIPT type="text/javascript">
<BODY onload="noBack();"    onpageshow="if (event.persisted) noBack();" onunload="">

The above method works in IE, Mozilla Firefox, Chrome and Safari.

This works great IE, Firefox and Chrome however it doesnt work on Safari.

So the best method to use is the following:-

<SCRIPT type="text/javascript">
function changeHashOnLoad() {
     window.location.href += "#";
     setTimeout("changeHashAgain()", "50"); 

function changeHashAgain() {
  window.location.href += "1";

var storedHash = window.location.hash;
window.setInterval(function () {
    if (window.location.hash != storedHash) {
         window.location.hash = storedHash;
}, 50);
<BODY onload="changeHashOnLoad(); ">

Let us know of any corrections or improvements.

Warn User if Back is Pressed

Preventing users from going back using the back button is something that gets asked every now and again.

So if you want to warn a user if the “back button” is pressed then you can use the following javascript snippet:-

window.onbeforeunload = function() { return "If you go back your work will be lost."; };

This will add a warning message which opens in the browser when the back button is pressed. The problem is that is can sometimes with certain browsers pop up when you do not want it to.