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)
July 11th, 2007 at 4:19 pm
That worked very well. I always thought the back button was a web application’s worst nightmare.
Thanks!
September 28th, 2007 at 9:27 am
This is still not working with Firefox.
March 21st, 2008 at 12:28 pm
it is not working in firefox .
plx if u have any other solution .
then mail me i will be very thankfull
May 15th, 2008 at 3:11 pm
As of 2008/05/15, it still doesn’t work in firefox.
June 25th, 2008 at 9:39 am
This works in IE and FireFox :
function noBack(){ window.history.forward(); }
July 1st, 2008 at 11:50 am
Martin,
I don’t get it. What calls the function noBack ?
July 18th, 2008 at 11:21 am
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
July 20th, 2008 at 10:45 am
By the way, it should be reminded that history.forward() method never gets any parameter. It is equivalent to history.go(1).
August 11th, 2008 at 3:54 pm
An elegant yet simple solution, works in FireFox too. Thank you so much for this.
August 20th, 2008 at 6:57 am
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.
August 20th, 2008 at 7:18 am
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.
March 2nd, 2009 at 5:44 pm
It works fine for me in FireFox but does not work on IE 6.0.2. Can anybody please help
March 16th, 2009 at 4:36 am
Yes, this works well in IE, Firefox and Opera (not tried Safari)
Thanks!
April 10th, 2009 at 9:36 am
Simple Solution ….. Keep it Up…
June 5th, 2009 at 5:46 pm
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!
June 8th, 2009 at 10:22 am
I also do Weddings and Bar Mitzvas!
Glad it worked out.
June 18th, 2009 at 8:08 am
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?
June 22nd, 2009 at 10:12 am
it is not working in mozilla firefox 3.0.11
June 24th, 2009 at 11:06 am
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)}
July 30th, 2009 at 1:53 pm
I try in firefox 3.0.11 and works fine.
Thanks
October 7th, 2009 at 3:54 am
it is not working in safari 4 and opera 10
April 14th, 2010 at 6:03 pm
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)}
July 23rd, 2010 at 6:23 pm
Thanks Martin I was searching for this solution from the last two days thank you so much!!
December 10th, 2010 at 2:31 pm
Works fine in mozilla.. Thanks a lot for sharing.
April 7th, 2011 at 5:17 am
i try.but it is not working in firefox and IE
April 30th, 2011 at 2:04 pm
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…
April 30th, 2011 at 2:50 pm
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?
June 8th, 2011 at 1:24 pm
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.
June 8th, 2011 at 1:39 pm
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).
June 11th, 2011 at 4:23 am
Nice post works great….!!!
July 3rd, 2011 at 12:11 am
code run properly but one time page return the privious page
August 24th, 2011 at 9:17 am
It works fine but it requires reference on the page any how.
October 11th, 2011 at 12:38 pm
Thanks for the code…..its working fine with safari 5.1….
October 20th, 2011 at 2:07 pm
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
October 25th, 2011 at 9:15 am
Thanks it’s working.
November 18th, 2011 at 12:39 pm
Thanx to Martin.Your suggestion works for me effectively.
November 26th, 2011 at 7:45 am
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!
December 6th, 2011 at 5:42 pm
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.
December 6th, 2011 at 5:44 pm
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.
April 18th, 2012 at 10:53 am
Hi All,
I have posted the anser in my blog check it :
http://moretoc.blogspot.in/2012/04/disabling-back-button-on-browser-using.html
May 23rd, 2012 at 11:45 am
Thanks for this code.
June 10th, 2012 at 3:53 pm
thanks. it works.
June 26th, 2012 at 12:11 am
Dude, thank you, you saved my life.
August 29th, 2012 at 8:49 pm
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?
September 22nd, 2012 at 2:26 pm
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
January 22nd, 2013 at 8:30 am
This works for me, Thank you Alex
February 5th, 2013 at 6:24 pm
Code not working for me in any browser…. Wat could be the problem? someone plz help…. i am using IE 9 browser.
March 19th, 2013 at 10:22 am
hi… it does not work in Opera 12.10!