I want to disable the back and forward action in the browser to my page. So how to disable the back and forward actions of the browser.
-
5On the face of it, this is a bad idea. More details on why you want to do this are encouraged :) – JohnP May 24 '11 at 09:40
-
@JohnP - +1. I thought part of the point of unobtrusive JavaScript was to give the user *back* his Prev/Next buttons, not take them away entirely. : ) – John Green May 24 '11 at 09:41
-
see http://stackoverflow.com/search?q=disable+back+button – xkeshav May 24 '11 at 09:41
-
You could load everything with AJAX so that the actual URL isn't changing. I don't really see the use of it though - what is there about the back button that you'd like to disable it? – pimvdb May 24 '11 at 10:09
5 Answers
You can't. This is not something a browser exposes.
Regardless, this is a usability nightmare - I wouldn't recommend this, as having the back and forward buttons are things that users are very used to.
You can write your application in such a way that it "breaks" if back is used, but I would suggest that this would make your application mostly unusable to most people.

- 489,969
- 99
- 883
- 1,009
You can disable going back to a page using the following script in the head of your html.
<script type = "text/javascript" >
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>

- 43
- 1
- 11
whatch this SO question and answer and this SO Q&A
it's not exactly what you are looking for, but will give you an inspiration, how to react on user clicking back and forward buttons.
this jquery-plugin: jQuery history plugin is mentioned in both posts
Stumbled here from a google search. Hopefully this'll help those with the same issue.
After the mandatory mention of this usually being an usability problem, that should be solved elsewhere, I've found this to work in chrome 85:
<script type = "text/javascript">
history.pushState(null, null, location.href);
history.back();
history.forward();
window.onpopstate = function ()
{
history.go(1);
};
</script>
Lastrly, in all fairness, credit goes to the following thread:
https://support.google.com/chrome/thread/8721521?msgid=10849294

- 39
- 6
You can disable the back button by
window.history.forward(1);
Hope this helps...:)
Cheers...

- 1,439
- 7
- 20
- 35