Danya Lette

Command-Click Prevent Default


I often command-click links in order to open them in a new tab. I find it very irritating when a site’s JS usurps that functionality.

It turns out that click events have a boolean attribute – event.metaKey – that is true on command-click. So, you can event.preventDefault() your heart out and still easily retain the expected command-click behaviour.

    if (!event.metaKey) {
        // etc
    } else {
        //other stuff