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!
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.
Perhaps something like this?
function onclick(e){
var event = e ? e:window.event;
this.target = event.ctrlKey?"_blank":"_self";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With