How to disable browser\'s BACK Button (across browsers)?
Try this code. Worked for me. It basically changes the hash as soon as the page loads which changes recent history page by adding "1" on URL. So when you hit back button, it redirects to same page everytime.
<script type="text/javascript">
var storedHash = window.location.hash;
function changeHashOnLoad() { window.location.hash = "1";}
window.onhashchange = function () {
window.location.hash = storedHash;
}
</script>
<body onload="changeHashOnLoad(); ">
</bod>
<body onLoad="if(history.length>0)history.go(+1)">
There have been a few different implementations. There is a flash solution and some iframe/frame solutions for IE. Check out this
http://www.contentwithstyle.co.uk/content/fixing-the-back-button-and-enabling-bookmarking-for-ajax-apps
BTW: There are plenty of valid reasons to disable (or at least prevent 1 step) a back button -- look at gmail as an example which implements the hash solution discussed in the above article.
Google "how ajax broke the back button" and you'll find plenty of articles on user testing and the validity of disabling the back button.
If you rely on client-side technology, it can be circumvented. Javascript may be disabled, for example. Or user might execute a JS script to work around your restrictions.
My guess is you can only do this by server-side tracking of the user session, and redirecting (as in Server.Transfer, not Response.Redirect) the user/browser to the required page.
You should be using posts with proper expires and caching headers.
This seems to have worked for us.
history.pushState(null, null, $(location).attr('href'));
window.addEventListener('popstate', function () {
history.pushState(null, null, $(location).attr('href'));
});