tags:

views:

253

answers:

2

I want to prohibit the Back function of the browser. Therefore I write the following codes in html.

<body> 
<script type="text/javascript"> 
<!-- 
history.forward() 
//--> 
</script> 
</body>

but'The above "history.forward()" did not work suddenly when I coding html and some javascripts.

What's wrong? In addition, please teach the different method that had a similar function. Thanking you in advance.

+3  A: 

Using the history object

window.history.go(positive integer)

will take you forward through history, so

window.history.go(1)

will take you forward one page.

Also, make sure you're referencing the window object.

window.history.forward()

should also work

Ian Elliott
Thank you. I tried it. When I did Back somehow or other window.history.go(1); But, it seems not to be carried out. It was carried out if I reloaded it and did go in the fowrard pageDo I Have to code ?setInterval(function(){history.go(1);},1);
ffffff
you have to modify the _window_ object. window.history.go(1);
Ian Elliott
oops! I miss window object. Thanks!
ffffff
any reference to an object not defined with var will automatically be looked for in window, so that shouldn't matter
seanmonstar
+2  A: 

My recommendation is to not restrict the user's browser. Web browsers have back buttons and that's the way it is. You should architect your application so that it works when the user uses the back button, such as by expiring the page and properly handling the refresh of a previous page. If disabling the back button is some attempt at security, realize that there are ways around it, especially if javascript is disabled.

If I ended up on your site and found that everytime I hit the back button the page would ignore it I would be very unhappy. You can't know that you are the first site in the browsing history.

In my opinion, having javascript functionality to control the user's history was a bad addition.

Talljoe
There's some cases where disabling the back button could come in handy to prevent users from going back through forms etc. Hopefully this isn't a site wide feature.
Ian Elliott
I disagree. A multi-page form doesn't make this browser hijacking okay.
John Kugelman