在每个浏览器中的锚标签的“onclick”事件上按Ctrl或Shift效果 [英] Ctrl or Shift effects on the `onclick` event of an anchor tag in each browser

查看:199
本文介绍了在每个浏览器中的锚标签的“onclick”事件上按Ctrl或Shift效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现,当按下控件 Shift 键时,不同的浏览器会以不同的方式处理 onclick 事件。通过点击鼠标中键,它们的行为类似于以下链接。

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.

使用以下链接:

<a href="http://www.example.com/" onclick="alert('onclick');">go to example.com</a>

Onclick浏览器支持表

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        ?

有人可以填写我的问号吗?也;我想知道Chrome,Firefox,Safari和Opera的每个版本的行为是否不同。

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. :)

推荐答案

请参阅我的答案相关的问题。

这是由于用户使用点击修饰符键盘按钮时的预期行为 - 用户期望 Ctrl +单击链接以在新的选项卡或窗口中打开该链接。微软公司决定,由于用户期待这种行为,因此用户将不会点击 Ctrl +的唯一原因,因此,这种点击不会触发 onclick 事件在Internet Explorer。

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.

这篇关于在每个浏览器中的锚标签的“onclick”事件上按Ctrl或Shift效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆