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!!