单击链接时提示用户确认
我有一个链接可以执行一些潜在危险的功能(删除某些内容)。我想提示用户是否真的想这样做。我想用 javascript 来做,应该很简单。
到目前为止我的解决方案:
<a href='/delete' onclick='return confirm("Are you sure?")'>delete</a>
.. 很糟糕,它不是由 Firefox 和 IE 中的中键单击触发的。
<a href='/delete' onmousedown='return confirm("Are you sure?")'>delete</a>
..不起作用。即使单击“确定”后返回 true,也不会导航链接。
实施这个的正确方法是什么?
I have a link that does some potentially dangerous function (delete something). I want to prompt user if he really wants to do it. I want to do it with javascript and it should be very simple.
My solutions so far:
<a href='/delete' onclick='return confirm("Are you sure?")'>delete</a>
.. is bad in a way that it is not triggered by middle click in Firefox and IE.
<a href='/delete' onmousedown='return confirm("Are you sure?")'>delete</a>
.. does not work. Even if true is returned on clicking Ok, link is not navigated.
What is the correct way to implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
javascript
javascript
我刚刚为网上银行客户解决了这个问题。每当用户导航到第三方网站时,FDIC 都要求确认“减速”。我们希望做到不引人注意,让人们无法绕过。
我已经用 IE、Firefox、Chrome 和 Android 对此进行了测试——单击、右键单击、中键单击、Shift 单击、Shift F10、Enter、长按,等等(Firefox 是最难的)。要么你遇到减速带,要么你得到一个空白选项卡,你无法绕过它。
要实现此功能,只需按照正常情况编写链接并将“speedbump”添加到其类中即可。
I just solved this problem for an online banking client. FDIC requires a confirmation "speedbump" whenever the user is navigating to a third party site. We wanted to do it unobtrusively, and make it impossible to get around.
I've tested this with IE, Firefox, Chrome, and Android-- click, right click, middle click, shift click, shift F10, enter, long tap, everything (Firefox is the hard one). Either you get the speedbump or you get a blank tab, you can't get around it.
To make this work, just write your link per normal and add "speedbump" to its classes.