Ctrl + click on links with click handlers
I have a link (anchor) to which href is attached to go to a specific URL: "www.bla.com".
<a href='http://www.bla.com' /> I also have a click handler attached to a link that performs some actions and then opens an html view in the same window. Everything works perfectly.
However, when the user uses "ctrl + click" to open the link in a new tab / window, the click handler seems to take precedence and opens the html view in the same window. But I want to keep the behavior of "ctrl + click" and allow the user to open the link in a new tab / window (like a regular link). How can i do this?
Thanks in advance!
The linked click event object will have the ctrlKey property set to true if the control key (or equivalent) was pressed when the click occurred. Check the event object and pressing the control key, do not "HTML view".
<a href="#" onclick="alert(event.ctrlKey);">Click me!</a> However, if the user activates the link in some other way, you may or may not receive the click event.
eg.
- right button → "open in a new tab / window" - there is no click event (Firefox, IE)
- Tab, to focus on the link, press enter - dispatches a click event (Firefox, IE).