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:

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

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

    ReplyDelete
  3. 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

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

    ReplyDelete