Ctrl or Shift effects on the `onclick` event of an anchor tag in each browser

ぃ、小莉子 提交于 2019-12-10 13:43:36

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3023816/ctrl-or-shift-effects-on-the-onclick-event-of-an-anchor-tag-in-each-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!