1

Apart from the obvious onclick event handler, how can I detect if the user tabbed the link and hit enter or whatever other key/device that would make the link open?

Also, is it possible to detect a middle mouse button click (defaults to open in new tab)?

Razor
  • 27,418
  • 8
  • 53
  • 76

2 Answers2

1

Pressing enter will produce an onclick event. You do not need any special code to handle the enter key

Edit: As for middle click you can look here: http://www.quirksmode.org/js/events_properties.html It is not so simple (thanks to IE)

Edit: If you use jQuery it is very simple: How to distinguish between left and right mouse click with jQuery

Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341
1

Assuming you want a separate solution to catching specifically an ENTER key press on a link, you might be able to use onkeyup and check if the event.keyCode equals 13 (ENTER key).

mrjames
  • 232
  • 1
  • 5