Usually, when people click on a link, I have onclick bound to it. And then return false.
When people click with "control", they expect a new page to open up. Therefore, I want to ignore the onclick AND/OR detect it. How do I do this?
The event object has a "ctrlKey" boolean flag, so you can check that in your handler. It depends a little on your framework, but generally if your handler returns false then you'll have "defeated" the click.
In IE, the event object is a global (that is, a property of the "window" object). In other browsers, it's a parameter passed to the handler. A common idiom therefore is:
function clickHandler(theEvent) {
theEvent = theEvent || window.event;
// ...
}
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