views:

39

answers:

1

Hi,

I recently discovered that different browsers handle the onclick event differently when the control of shift key is pressed. Same thing for following links with the middle mouse button.

  <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 behaviour would be even nicer, but I don't think there is :).

Thanks a lot.

+1  A: 

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.

Andy E
BTW:I don't have the intention to change the behaviour of web browsers. I just need to measure commercial clicks (via some JavaScript library).I got this working for IE7 since tabbed browsing is getting more and more popular (also via right clicks). So some day we'll have to switch to a redirect method.
Erik