Jump to content

Deactivate "Back" function on browser


Jiasheng

Recommended Posts

Active server pages created by script are presented incorrectly when user uses the "back" button or the "back" link on mouse-activated drop-down list to return to previous screen. How can we de-activate the "back" function so that we can restrict user to use the "Return" button that we've provided on the Web page?If this cannot be done by Javascript, can you suggest an alternative method? Thank you very much!

Link to comment
Share on other sites

Well, I know you can take off the back function off some browsers by displaying what you want in a popup but without the Navigational things, but you can't do it to all browsers. Besides what stops a person from just hitting the backspace key (same as a "back" button). But from what I know, you can prevent a person for hitting the back button, but it's not foolproof. Or you can just simply ask them not to go back.

Link to comment
Share on other sites

I guess there is no foolproof way to stop users from going back with the "Back" button despite displaying a note prominently to warn them not to do so.What we need to do is to minimize the loss of data presented on a form when the user returns with the "Back" button. Data are retained correctly for inputs to text boxes, radio buttons and checkboxes. However, the data on selection boxes are not retained. Is there any solution to retrieve this data?Thank you!

Link to comment
Share on other sites

The only way of reducing the damage caused by the back button, is difficult but not done by just javascript. It would not be secure, as all javascript can be manipulated by the user. You should use the PHP language to output the data on conditions, and have variables that determine on what page you are. This is how I've done it at my own site that actually doesn't have any pages left in the history (I use header("location: ...") that replaces the document). But that is just rebuilding your entire website, as this manner demands a very complicated way of displaying pages, that must be organised etcetera.I don't think there is an easier way, but I can be wrong :)[*Edit:]What I have done is calculate on what page the user is, and storing a unique value in a SESSION that represents that page. Then PHP sends a location header to the user so that the next document replaces the former one. The location it would send is just the same document, but now the SESSION holds a different value for the page, so the document will show another page in the document. Now the user is viewing another page, but without the ability to go back to the previous one; it is not there :) But still, if you would choose this, this topic should then be moved to PHP forum :)

Edited by Dan The Prof
Link to comment
Share on other sites

Active server pages created by script are presented incorrectly when user uses the "back" button or the "back" link on mouse-activated drop-down list to return to previous screen.  How can we de-activate the "back" function so that we can restrict user to use the "Return" button that we've provided on the Web page?If this cannot be done by Javascript, can you suggest an alternative method?  Thank you very much!

This should work.If the button is not pressed then the current page will always be loaded.If it is pressed then you will go to the new page.
<head><script>val=false;function check(){  if(val) window.location="http://www.google.com";else window.location=window.location;}function set(){ val=true;}</script></head><body onunload="check()"><input type="button" value="go" onclick="set();check()" /></body>

Link to comment
Share on other sites

Couldn't you just do:

<head><script>val=false;function check(){return false;}</script></head><body onunload="check()"></body>

To stop the user from leaving at all? :)

Link to comment
Share on other sites

Couldn't you just do:....................To stop the user from leaving at all? :)
Well no, if you read what he asks for:
How can we de-activate the "back" function so that we can restrict user to use the "Return" button that we've provided on the Web page?
He wants the user to be able to leave, but only when they press a button on the page other than the back button.The code you posted would never allow the user to leave the page.
Link to comment
Share on other sites

This should work.If the button is not pressed then the current page will always be loaded.If it is pressed then you will go to the new page.
<head><script>val=false;function check(){  if(val) window.location="http://www.google.com";else window.location=window.location;}function set(){ val=true;}</script></head><body onunload="check()"><input type="button" value="go" onclick="set();check()" /></body>

Yes, this works. Thanks!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...