469,610 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

How to disable browser's BACK button?

15
how can i disable the back button for a browser?

I have been reading a lot of forums but cant find any answer to it...other than opening up the page, in which i want to disable the browser in a new window(which i dont want to do)

Is their a way to do it? using javascript or something?

I have tried using the following but non of them actually disable the
back button:

window.history.forward(1); -- does not disable the back button

location.replace(URL) -- keeps flickering my page

3 approahes from:
http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911 -- but of no use for me
Nov 1 '07 #1
6 29227
balabaster
797 Expert 512MB
how can i disable the back button for a browser?

I have been reading a lot of forums but cant find any answer to it...other than opening up the page, in which i want to disable the browser in a new window(which i dont want to do)

Is their a way to do it? using javascript or something?

I have tried using the following but non of them actually disable the
back button:

window.history.forward(1); -- does not disable the back button

location.replace(URL) -- keeps flickering my page

3 approahes from:
http://www.htmlgoodies.com/tutorials...le.php/3478911 -- but of no use for me
I don't recall the JavaScript syntax, but if I recall correctly you just have to clear the history object in memory which keeps a list of all the pages visited since you opened the instance of the browser....however you don't have access to the browser's actual history for obvious security reasons. An alternative is to keep a session variable open on the user's session to keep tabs on the page they're supposed to be on so they can't skip back and forth. This will ensure that someone goes through your web pages in the right order (i.e. for an online exam or something).

JavaScript isn't foolproof because someone could turn off their javascript and bypass your mechanism. My recommendation is using the session mechanism on the server side.

If you're intent on JavaScript you can always replace the location of the previous history slot with the name of the current location...something akin to
Expand|Select|Wrap|Line Numbers
  1. window.history.back(0) = window.location
I forget if the history is in reverse order or not...so you might have to find out the length of the history and replace the value in parenthesis with length-1. This also does't bypass the little drop menu on the back button so here, clicking the back button would cease to take them to anywhere but your page, but they could bypass it by choosing one of the items in the drop menu which would effectively bypass your code.

Like I said though, that option isn't failsafe...and when they hit back the screen will essentially reload, so yes, you'll get a flicker.
Nov 2 '07 #2
mzmishra
390 Expert 256MB
i am not sure if you can disable browers back button progarmatically.

But there are soem approaches to achieve that functionality
see the article below
http://bucarotechelp.com/design/jseasy/95070401.asp
Nov 2 '07 #3
sspost
15
for window.history.back(0) = window.location

where do i write this code?
i wrote in <head> but it doesnt work....
Nov 5 '07 #4
balabaster
797 Expert 512MB
for window.history.back(0) = window.location

where do i write this code?
i wrote in <head> but it doesnt work....
You would have to do fire a JavaScript from the Page OnLoad event

<Page OnLoad="javascript:MyFunction();">

Bear in mind that the function call in your OnLoad event is case sensitive just like JavaScript is.

Something similar could also be done with the meta tag http-refresh...I forget exactly how that works but if you google "pragma"+"http-refresh" you should find some info.

And the method using ASP/ASP.NET would be just to serve up whatever page they're supposed to be looking at by keeping tabs on the page they're currently looking at and then no matter what they click serve them up the next allowable page by using the response.redirect method This has to be called prior to anything being written to the page though, or it won't work.
Nov 5 '07 #5
sspost
15
It doesnt work for me...i dont know why
when i click the back button instead of going to previous page it goes to a page before that ...i dont know whats wrong

either i want to disable the back button or
i want when i click the back button all the values enetered by user in the previous page should be their ..which are getting lost...because of which i added my own button and storing all the values from the previous page in session varaibles

i added the script:
Expand|Select|Wrap|Line Numbers
  1. var ie = (window.navigator.appName == "Microsoft Internet Explorer") ? true : false;
  2.          function setEventByObject(object, event, func){
  3.          if (!ie){
  4.          object.addEventListener(event, func, false);
  5.          } else {
  6.          object.attachEvent("on" + event, func);
  7.          }
  8.          }
  9.          setEventByObject(window, "unload", exitme);
  10.  
  11.  
  12.           function jumpforward(){
  13.           if(window.location.href.indexOf("jumpforward")!=-1) { 
  14.           history.forward();
  15.           }
  16.  
  17.           }
  18.  
  19.           var block = "true";
  20.  
  21.           function exitme()
  22.           {
  23.           if(block == "true") 
  24.           {
  25.           if(window.location.href.indexOf("?")==-1) 
  26.           {
  27.            window.location.href += "?jumpforward";
  28.            } else if (window.location.href.indexOf("jumpforward")==-1)
  29.            {
  30.             window.location.href += "&jumpforward";
  31.            }
  32.               jumpforward();
  33.           }
  34.          }
  35.  
but it would fire on all the buttons on the page ...i am not sure whats wrong with it...i am not very gud @ javascript?

can someone please help figure out whats wrong?
Nov 6 '07 #6
Shashi Sadasivan
1,435 Expert 1GB
javascript control on the browser buttons should be termed as going obsolete.
As mentioned above, the user might disable javascripts. But you can load the page only if javascript is enabled (which makes sure javascripts will work)

However, that will still not stop the cause of the web pages being stored on the system, And if theu user has a desktop search (like of live and google desktop) any sensitive information will be indexed....not good at all..

use the HttpCacheability.NoCache in your pages. (generally i would put that into a master page , including checking is a user is logged in and all those standard things)

that will tell the browser not to store any web pages sent to it. and so if the back button is pressed, the page dosent exist with the user, so it will never go back. :)
Nov 6 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Dmitri Shvetsov | last post: by
3 posts views Thread by sonu | last post: by
6 posts views Thread by Raghu Raman | last post: by
3 posts views Thread by Paul | last post: by
1 post views Thread by Terry Olsen | last post: by
16 posts views Thread by Barry Gilmore | last post: by
9 posts views Thread by Joe Delphi | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.