Link to home
Start Free TrialLog in
Avatar of PlacesForPeople
PlacesForPeopleFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Disable Mouse Back button with javascript

Mouse Back Button: Question:
Hi all,

Have an application where I need to disable where back is used. I currently disable toolbars, disable right click and disable the backspace key, my mouse has 5 buttons and one of these goes back.

Is there a way to stop this from going back?  I have looked everywhere and can't seem to find a valid solution

Thanks,
John
Avatar of silemone
silemone
Flag of United States of America image

you can't truly disable back button...you can make it where the page can't go backwards though...the only true way to disable this is to open a new window where there is no where to go back to...
I don't think there would be a valid way to do this 100% of the time. The back button is a feature of the browser that can not be disabled. It can be hidden, but many browsers also have other keyboard short cuts for the back button, and these days, most browsers will not allow you to disable right click.

But, there is a way that seems to work somewhat:

We will have PageA and PageB. PageA is simply a blank page that will immediatly redirect to PageB. PageB is your page with the actual content. When the user tries to go back, they go back to PageA, which in turn will immediatly redirect them back to pageB.

If your concerns for this deal with an AJAX application, you can use anchors to make the back and forward buttons function as you would expect. Every time something changes in the application, you need to "redirect" to the same page with an anchor at the end that represents the current state (url.com/index.php#tab_options). When a browser redirects to the same page with an anchor attached, most browsers will NOT reload the page, and all of the anchors used will show up in the back/forward history.
the only way as stated is to either call page in new window...and close old


http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
read the last couple headers:  If you truly want to control history which the back button is tied to...
again:  another example:

http://www.irt.org/script/311.htm
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Impossible to completely disable the back button. Depends on the client (Browser) executing the code, and on the fact that Java Script is enabled and no proxy exists that will filter out the code.

Think of another way, unless you know that the client is IE 7 for example for internal use.

If you're writing merchant processing code, deal with form "repost" (duplicate order submission) on a transactional level (data layer and db), not on the client level.


Avatar of PlacesForPeople

ASKER

Thanks for all of your comments.  I will look for a work around through some of the links you have sent through.

At the minute our browser is IE6 but will no doubt be IE7 by some time next year.  I didn't think there would a way to completely remove the back function but it looks like it isn't possible to completely control the events on an internet mouse.