

Ask HN: Please stop hijacking onclick on HTML links - mschuster91

I do not know why it is "en vogue" now to hijack the "onclick" event on links. From Google (which changes the href-attribute in search results to their redirector - yay for loading times on mobile) to Twitter (adding their own URL shortener on already shortened links) to news and porn sites preventing the middle click from opening in a new tab!<p>Please, stop messing with the way I browse the web, be it for marketing or whatever other reason.
======
J_Darnley
Congratulations, you have found one of the things I would remove from the
javascript features of a browser if I had the skills to do so.

------
seiji
You need to make sure your click handlers detect meta keys:

    
    
            navToThing: (e) ->
                if not (e.ctrlKey or e.metaKey)
                    e.preventDefault()
                    @navigate e.currentTarget.pathname
    

If someone is holding down a meta key when they click a link, get the hell out
of the way and just let the event happen. If they click without a modifier,
feel free to prevent the event and continue updating the state of your fancy
one-page app.

Sadly, most sites just copy/paste javascript from ten year old beginner PHP
tutorials and will never detect meta keys to allow for open-in-new-tab.

~~~
martin-adams
As someone who hasn't explored this much, why is a meta key problematic?

~~~
seiji
I think most people open-in-new-tab by command or control clicking on a link.
The event handler can detect the key being held down while you click a link.

We're basically guessing their intent and not running preventDefault if they
are trying to open things in a new tab.

~~~
mschuster91
Exactly... and we're already "guessing intents" way too much! It's all Apple-
style, leave the user with as few choices as possible.

