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) {

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

48 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.


  • 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:


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

  • Martin Says:

    Just insert this in the head section :

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

    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()}

    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);}

    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)

  • 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:

    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]

    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 –

    I’ve used following piece of code as well:
    function noBack(){window.history.forward()}

    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()}

  • carlos_ulrich Says:

    I try in firefox 3.0.11 and works fine.

  • 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(){

  • Shariff Says:

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

  • Antony Says:

    Works fine in mozilla.. Thanks a lot for sharing.

  • vijay Says:

    i try.but it is not working in firefox and IE

  • Amin Says:

    This is not working, i try to find this thinks to all the website but nobody give me the best or provable replay.
    This is fake in short…

  • harel Says:

    I dont think I understand what you’re trying to ask here… In what browser is this not working? Who did you ask? What reply you were hoping to get?

  • user Says:

    don’t you know it is creepy to interfere with a person’s ability to get out of a website, and the result is a loss of business for the website owner. any programmer that would suggest this, or has done it, would be fired from my company at once. you people disgust me. and you don’t get my name or email because you cannot be trusted to act ethically.

  • harel Says:

    :) I’ll assume for argument’s sake that you are not a troll and actually meant that seriously. This is not intended for ‘websites’. Its for internal applications where the back button counters the flow of the application logic. This was a solid requirement in case management systems for social services, for example.
    You did made me chuckle. Thanks :)
    (And assuming you are serious: I’m very happy I don’t have to work for you and wish to send my condolences for those who do).

  • aneeshkumar Says:

    Nice post works great….!!!

  • amit Says:

    code run properly but one time page return the privious page

  • Dipul Patel Says:

    It works fine but it requires reference on the page any how.

  • RAJ SINHA Says:

    Thanks for the code…..its working fine with safari 5.1….

  • kirubakaran Says:

    The above code is very much useful for me before going throw this site i had never used this method it fine and working too

  • Suri Says:

    Thanks it’s working.

  • sandipan Says:

    Thanx to Martin.Your suggestion works for me effectively.

  • Hana Says:

    It’s working fine in IE8.0, FireFox 8.0, Safari 5.1.1, Google Chrome 15.0.874!
    But is not working Opera 11.50!

  • David Cherry Says:

    Thanks! I’ll try these suggestions. But many comments on the Internet express such hostility to disabling the back button that I fear for my life. Maybe this can hinder (if not prevent) students from blindly guessing at online homework questions again and again until they get all the right answers. No IT support, no server, and I’m just an amateur.

  • harel Says:

    If you need to disable the back button and have a good enough reason for it, by all means don’t listen to anyone on the ‘internet’. Its only a problem if its done for the wrong reason or solves a problem that either didn’t exist or can be solved in other ways.

  • subhajit lahiri Says:

    Thanks for this code.

  • Free Says:

    thanks. it works.

  • ElDie Says:

    Dude, thank you, you saved my life.

  • ramon Says:

    Hey, could anybody explain me what the ethical problem is? If you don’t like the back button keeping you in the same page, then close your tab or reopen your browser. What is wrong with that?

  • John Says:

    It does not work for me since it is trying to obtain a non-cached POST request from the browser history. It trys to go to page and can’t find it before it does the forward. Any suggestions? Thanks

  • jegadeesh Says:

    This works for me, Thank you Alex

  • Sid Says:

    Code not working for me in any browser…. Wat could be the problem? someone plz help…. i am using IE 9 browser.

  • Hussain Says:

    hi… it does not work in Opera 12.10!

Leave a Reply