Ctrl 或 Shift 对每个浏览器中锚标记的“onclick”事件的影响
我最近发现,当按下 Control 或 Shift 键时,不同的浏览器以不同的方式处理 onclick
事件。它们在通过单击鼠标中键来跟踪链接的行为上也有类似的分歧。
链接如下:
<a href="http://www.example.com/" onclick="alert('onclick');">go to example.com</a>
Onclick 浏览器支持表
Mouse Keyboard Chrome Firefox Safari Opera IE5.5 IE6 IE7 IE8 IE9
Left None yes yes yes yes yes yes yes yes yes
Left Ctrl yes yes yes yes ? yes no no ?
Left Shift yes yes yes yes ? yes yes yes ?
Middle None yes no yes no ? N/A no no ?
有人可以帮我填写问号吗?还;我想知道 Chrome、Firefox、Safari 和 Opera 每个版本的行为是否有所不同。
在这种行为中找到一种逻辑模式会更好,但不幸的是,我认为不存在这种模式。 :)
I recently discovered that different browsers handle the onclick
event differently when the Control or Shift keys are pressed. They diverge similarly on behavior for for following links by clicking the middle mouse button.
With the following link:
<a href="http://www.example.com/" onclick="alert('onclick');">go to example.com</a>
Onclick browser support table
Mouse Keyboard Chrome Firefox Safari Opera IE5.5 IE6 IE7 IE8 IE9
Left None yes yes yes yes yes yes yes yes yes
Left Ctrl yes yes yes yes ? yes no no ?
Left Shift yes yes yes yes ? yes yes yes ?
Middle None yes no yes no ? N/A no no ?
Can someone please fill in the question marks for me? Also; I'm wondering if the behaviour differs for each version of Chrome, Firefox, Safari and Opera.
Finding a logical pattern in this behavior would be even nicer, but I don't think there is one, unfortunately. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅我的回答< /a> 相关问题。
这是由于用户使用点击修饰符键盘按钮时的“预期行为” - 用户期望 Ctrl + 单击链接以在新选项卡或窗口中打开该链接。 Microsoft 的小伙子们认为用户 Ctrl+ 单击的唯一原因是因为他们期望这种行为,因此,此类单击不会触发 Internet Explorer 中的
onclick
事件。See my answer to a related question.
This is due to the "expected behaviour" when a user uses click-modifier keyboard buttons - the user expects Ctrl+Click on a link to open that link in a new tab or window. The chaps at Microsoft decided that the only reason a user would Ctrl+click because they were expecting that behaviour, thus, such clicks do not fire the
onclick
event in Internet Explorer.