How to Disable the Browser Back Button

Its quite simple to disable the back button functionality of a browser (this was tested on IE and Firefox).

if (window.history) {
window.history.forward(1);
}

This causes every back to return with a forward. Works a treat ;o)


23 Responses to “How to Disable the Browser Back Button”

  • Mike Knizeski Says:

    That worked very well. I always thought the back button was a web application’s worst nightmare.

    Thanks!

  • Elison Nayak Says:

    This is still not working with Firefox.

  • savita Says:

    it is not working in firefox .
    plx if u have any other solution .
    then mail me i will be very thankfull

  • kchocm Says:

    As of 2008/05/15, it still doesn’t work in firefox.

  • Martin Says:

    This works in IE and FireFox :

    function noBack(){ window.history.forward(); }

  • Alex Says:

    Martin,

    I don’t get it. What calls the function noBack ?

  • Martin Says:

    Just insert this in the head section :

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

    MSIE, Firefox, Safari, Opera

  • Martin Says:

    By the way, it should be reminded that history.forward() method never gets any parameter. It is equivalent to history.go(1).

  • Ra88 Says:

    An elegant yet simple solution, works in FireFox too. Thank you so much for this.

  • Alex Says:

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

    This code doesn’t work correctly in Safari.

  • Alex Says:

    I found here a solution to the “Safari’s Bug”. Just change the code to:

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

    The “setTimeout” function fixed my problem.

  • naren Says:

    It works fine for me in FireFox but does not work on IE 6.0.2. Can anybody please help

  • Brian Says:

    Yes, this works well in IE, Firefox and Opera (not tried Safari)
    Thanks!

  • Ibrahim Says:

    Simple Solution ….. Keep it Up…

  • Deana Says:

    You are my friggin hero! I’ve been searching for 3 days for a solution in firefox and NOTHING ONLINE WORKED….until I found this post of course. Thanks a million!

  • harel Says:

    :o )
    I also do Weddings and Bar Mitzvas!
    Glad it worked out.

  • ABCD Says:

    Joined: Jun 18, 2009
    Messages: 1

    [Post New]posted Today 12:50:23 PM
    Quote Edit [Up]
    Hi,

    I’m using the cache-control method to use page expiration utility in my JSP.
    Its working fine with IE. But, I’m not able to achieve this with Mozilla Firefox.
    I’m setting all the cache-control related attributes to achieve this in my JSP -
    Also,

    I’ve used following piece of code as well:
    function noBack(){window.history.forward()}
    noBack();
    window.onload=noBack;
    window.onpageshow=function(evt){if(evt.persisted)noBack()}
    window.onunload=function(){void(0)}

    But, still, page is not getting expired in Mozilla.
    Can any one of you suggest me any other work around?

  • ajay Says:

    it is not working in mozilla firefox 3.0.11

  • Martin Says:

    It does work.
    Don’t forget to insert this script in the header of every page :
    function noBack(){window.history.forward()}
    noBack();
    window.onload=noBack;
    window.onpageshow=function(evt){if(evt.persisted)noBack()}
    window.onunload=function(){void(0)}

  • carlos_ulrich Says:

    I try in firefox 3.0.11 and works fine.
    Thanks

  • prihanto Says:

    it is not working in safari 4 and opera 10

  • Rajasekar Says:

    Included this in a jsp and it works! Thanks !

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

  • Shariff Says:

    Thanks Martin I was searching for this solution from the last two days thank you so much!!

Leave a Reply