JavaScript的 - 检测浏览器的停止按钮点击 [英] JavaScript - detect browser stop button click
问题描述
我有禁用提交按钮,点击它时,一种形式。
但是,如果用户点击浏览器停止按钮。
然后,他将不能够重新提交表单。
I have a form that disables submit button, when it is clicked. But what if the user clicks browser "Stop" button. Then he will not be able to resubmit the form.
有什么办法来处理这样的情况下,有可能检测停止按钮preSS?
Is there any way to handle such cases, possibly detecting Stop button press?
推荐答案
禁用提交按钮的原因是什么?
What is the reason for disabling the submit button?
您正试图避免双重点击? - >您可以禁用的只是一段短暂的时间提交按钮,再重新启用它超时
You are trying to avoid double-clicks? -> you can disable the submit button for only a brief period of time, re-enabling it again on a timeout.
您正试图避免急躁重载击? - >是相同的,但具有较长的待用期间
You are trying to avoid impatient reload-clicking? -> the same, but with a longer inactivity period.
您试图阻止表单提交两次导致出现重复的动作? - >你无法抗拒这只是禁用按钮,如去后退/前进将导致页面重新加载,有可能保持旧表的内容,但不是disabledness状态,除非短路,bfcache。在这种情况下,你必须创建一个不能多次使用一个一次性使用的令牌或新的项目编号,并把它放在一个隐藏字段的形式。服务器可以检查它并禁止重复。
You are trying to stop a form being submitted twice causing duplicate actions to occur? -> you can't fight this just with button disabling, as going back/forward will cause the page to be reloaded, likely keeping old form content but not the disabledness state, unless short-circuited by bfcache. In this case you must create a one-use token or new item ID that cannot be used more than once, and put it in a hidden field in the form. The server can check for it and disallow duplicates.
可能检测停止按钮preSS?
possibly detecting Stop button press?
不要的onStop
,这不是真的可靠。除了浏览器支持的问题,它不能赶上导航的所有可能的组合,并停止/重载/等。你永远不会知道服务器脚本多远了,不管执行的操作。
Avoid onstop
, it's not really reliable. Apart from browser support issues, it can't catch all possible combinations of navigation and stop/reload/etc. You'll never know how far the server script got, whether it performed an action.
这篇关于JavaScript的 - 检测浏览器的停止按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!