472,342 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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

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

Similar topics

21
by: Tony Marston | last post by:
If the use of the browser's BACK button is interfering with the operation of your web application then take a look at this article entitle "Back...
2
by: Dmitri Shvetsov | last post by:
Hi All, Is it possible to disable the backspace button in browser? I wrote a login page, then after login I can allow the user to work in the...
3
by: sonu | last post by:
I want to disable the browser referesh and back button. is there any way in .net for above. Regards Amit
6
by: Raghu Raman | last post by:
Hi, we are doing an in house project in c#.net(asp.net).We wanted to close our application when ever the user presses the SIGNOUT button. Even...
3
by: Paul | last post by:
Hi, just wondering if there is a way to disable the back button of the browser as I have a logoff page and would like to not allow the back...
1
by: Terry Olsen | last post by:
Is there any way to disable the client browser "Back" and "Forward" buttons while on my site? Or how would I go about knowing that a page hit is...
16
by: Barry Gilmore | last post by:
Is there a way to disable a button after it is clicked? I am trying to avoid having someone click on it twice while they wait for it to process....
9
by: Joe Delphi | last post by:
Hi, When users log out of my web application, I want to disable the back button so that they cannot "back into" the application after they have...
5
by: sethia4u | last post by:
Dear Programmers, when I click on logout button I redirect my page to login page again, session variables to null, but when I click on back...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.