Disabling Back button on the browser [closed]

2018-12-31 18:12发布

I am writing an application that if the user hits back, it may resend the same information and mess up the flow and integrity of data. How do I disable it for users who are with and without javascript on?

13条回答
怪性笑人.
2楼-- · 2018-12-31 18:42

Whatever you come up with to disable the back button might not stop the back button in future browsers.

If its late in the development cycle I suggest you try some suggestions above but when you get time you should structure your flow so that the back button does not interfere with the logic of your site, it simply takes the user back to the previous page like they expect it to do.

查看更多
墨雨无痕
3楼-- · 2018-12-31 18:42

I was able to accomplish this by using:

 Response.Cache.SetExpires(DateTime.MinValue);
 Response.Cache.SetNoStore();

When I used Response.Cache.SetCacheability(HttpCacheability.NoCache); it prevented me from downloading office files.

查看更多
宁负流年不负卿
4楼-- · 2018-12-31 18:43

It is true, proper validation should be added to make sure duplicate data doesn't mess things up. However, as in my case, I don't full control of the data since I'm using some third party API after my form. So I used this

history.go(+1);

This will send user forward to the "receipt" which is supposed to come after "payment" page if they try to go back to "payment" page (just giving a payment for example). Use sparingly, though

查看更多
心情的温度
5楼-- · 2018-12-31 18:45

4 Guys from Rolla wrote this article on disabling the back button a long time ago (in a galaxy far far away): http://www.4guysfromrolla.com/webtech/111500-1.shtml

查看更多
公子世无双
6楼-- · 2018-12-31 18:46

You could post the data on each form to a _NEW window. This will disable the back button on each window, but without javascript it might be difficult to force the old one closed.

查看更多
伤终究还是伤i
7楼-- · 2018-12-31 18:47

It is possible to disable back button in all major browser. It just uses hash values to disable the back button completely. Just put these 5 lines of code in your page

 <script>
window.location.hash="no-back-button";
window.location.hash="Again-no-back-button";//for google chrome
window.onhashchange=function(){window.location.hash="no-back-button";}
</script> 

Detailed description

查看更多
登录 后发表回答