问题
I have a link (anchor) that has an href attached to it to navigate to a specific URL say 'www.bla.com'.
<a href='http://www.bla.com' />
I also have an click handler attached to the link that performs some actions and then opens an html view in the same window. Everything works perfectly well. 
However, when the user uses 'ctrl+click' to open the link in a new tab/window, the click handler seems to be taking precedence and opens the html view in the same window. But I want to retain the 'ctrl+click' behavior and allow the user open the link in a new tab/window (just as a normal link). How could I do that?
Thanks in advance!
回答1:
function process(e){
   var evt = e ? e:window.event;
   if(evt.ctrlKey)
      alert("ctrlClicked");
}
evt.ctrlKey will return true if control key is pressed, you can write your conditions within "if" block, I tested this for chrome and ff only.
回答2:
Perhaps something like this?
function onclick(e){
   var event = e ? e:window.event;
   this.target = event.ctrlKey?"_blank":"_self";
}
    回答3:
The associated click event object will have its ctrlKey property set to true if the control key (or equivalent) was pressed when the click occurred. Check the event object and if the control key was pressed, don't do the "HTML view" thing.
<a href="#" onclick="alert(event.ctrlKey);">Click me!</a>
However, if the user activates the link some other way, you may or may not get a click event.
e.g.
- right button -> "open in new tab/window" - no click event (Firefox, IE)
 - Tab to focus on link, press enter - dispatches click event (Firefox, IE)
 
回答4:
<a target="_blank" href='http://www.bla.com' />
Add target="_blank" within to anchor tag.
来源:https://stackoverflow.com/questions/13262669/ctrlclick-on-links-with-click-handlers