5

Duplicate:


I have to disable back and forward button of browser ( IE and Firefox both ). I have tried:

//disable back button
window.onbeforeunload= function() { }   
window.history.forward(1);

but this works only in IE.
Is there any foolproof solution?

Community
  • 1
  • 1
  • i wish our client to be intelligent enough to understand your replies. :) –  Apr 23 '09 at 08:11
  • If telling them that it's technically not possible does not work, asking him to show you a single site that does exactly what they need should be sufficient. – soulmerge Apr 23 '09 at 08:15
  • 7
    It's simple. It cannot be done, nor is it reasonable to do it if it is possible: you have no right to take control of the end-users browser, even less to override very well defined behaviours. – annakata Apr 23 '09 at 08:15

4 Answers4

14

The answer is "no". You cannot disable a browser's back button.

Or at least on a good browser.

zombat
  • 92,731
  • 24
  • 156
  • 164
10

I believe this question has already been asked:

Disabling Back button on the browser Prevent Use of the Back Button (in IE)

If you're trying to prevent the user from losing their work, try something like:

window.onbeforeunload = function() { return "You work will be lost."; };

Steve

Community
  • 1
  • 1
Steve Harrison
  • 121,227
  • 16
  • 87
  • 72
  • yes we can use window.onbeforeunload= function() { return "so you want to go."; }, this will show wht you are saying. But i really don't want this thing. –  Apr 23 '09 at 08:05
3

There is no solution for that problem. You can't really "disable" it.

Martin K.
  • 4,669
  • 7
  • 35
  • 49
2

I would argue you should not disable the back button it at all possible as users are used to using it and it will frustrate them to find its functionality removed.

The users flow will be interrupted and they will leave your site.

Paul Whelan
  • 16,574
  • 12
  • 50
  • 83