问题描述
当用户点击后退按钮时,浏览器要求显示无处不在的此页面已过期消息的要求是什么?
What is the requirement for the browser to show the ubiquitous "this page has expired" message when the user hits the back button?
有哪些用户友好的方法可以阻止用户在webapp中使用后退按钮?
What are some user-friendly ways to prevent the user from using the back button in a webapp?
推荐答案
嗯,默认情况下,无论何时处理表单POST,然后用户点击然后刷新,他们都会看到指示浏览器正在重新提交数据的消息。但是如果页面设置为立即过期,那么他们甚至不必点击刷新,当他们回击时他们会看到该页面已经过期消息。
Well, by default whenever you're dealing with a form POST, and then the user hits back and then refresh then they'll see the message indicating that the browser is resubmitting data. But if the page is set to expire immediately then they won't even have to hit refresh and they'll see the page has expired message when they hit back.
To避免这两个消息有几件事要尝试:
To avoid both messages there are a couple things to try:
1)使用表格GET代替。这取决于你正在做什么,但这并不总是一个好的解决方案,因为GET请求仍有大小限制。信息在查询字符串中传递,这不是最安全的选项。
1) Use a form GET instead. It depends on what you're doing but this isn't always a good solution as there are still size restrictions on a GET request. And the information is passed along in the querystring which isn't the most secure of options.
- 或 -
2)在表单POST后执行服务器端重定向到其他页面。
2) Perform a server-side redirect to a different page after the form POST.
看起来类似的问题在这里得到解答:
Looks like a similar question was answered here:
作为第三种选择,可以防止用户回到他们的浏览器中。我唯一觉得有必要这样做是为了防止他们做一些愚蠢的事情,比如付两次钱。虽然有更好的服务器端方法来处理它。如果您的站点使用会话,那么您可以通过首先在结帐页面上禁用缓存并立即将其设置为过期来阻止他们支付两次。然后你可以利用存储在会话中的某种标志,如果你回到它会实际改变页面的行为。
As a third option one could prevent a user from going back in their browser at all. The only time I've felt a need to do this was to prevent them from doing something stupid such as paying twice. Although there are better server-side methods to handle that. If your site uses sessions then you can prevent them from paying twice by first disabling cache on the checkout page and setting it expire immediately. And then you can utilize a flag of some sort stored in a session which will actually change the behavior of the page if you go back to it.
这篇关于显示“网页已过期”在后退按钮上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!