Tuesday, February 28, 2006

Javascript to disable user from using the browser’s Back button

The following Javascript code would disable the user from using the browser's Back button.

<script language="javascript">
window.history.forward(1);
</script>

4 comments:

J-Fleaux said...

hee hee nice trick...I can hear them cursing now

ray said...

this hack no longer works on firefox... please find another way!!!

martin72 said...

Just insert this within head section :


function noBack(){window.history.forward()}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack()}
window.onunload=function(){void(0)}


It works with IE, Firefox, Safari, Opera

martin72 said...

Please note that history.forward() never gets any param.
It's equivalent to history.go(1).