5 ms·
Above all, please respect that a middle mouse button is supposed to open a link in a new tab.
by qwertox 3y ago
Above all, please respect that a middle mouse button is supposed to open a link in a new tab.
- worldsayshi 3y agoOh, I always use ctrl click. Ditto.
- Akronymus 3y agoToo often, links are just buttons that navigate you to the url when you click on it. It just ignores modifiers. It makes me furious
- worldsayshi 3y agoYeah as a user I'm annoyed how often modifiers are circumvented. As a developer I'm annoyed at how often I end up in a situation where I have to reinvent 'click to follow a link' and where it's really tedious to also reimplement modifiers.
- Alifatisk 3y agoAnd on mouspads or touch?
- tuyiown 3y agoNote, I've been using trackpads exclusively instead of mouse since 12 years now, before that, I had a mouse with extra buttons that I used a lot, including the open in new tab middle click. Not before reading your comment I had realized I never missed those extra buttons, or at least remembering missing them. And I realize that while my implementation takes care of modifiers to open links in new tabs on my web apps, I always overlooked middle button. The real problem though is that the web is very broken for building apps, and that the DOM API is missing a way to negociate the url changes on default clicked link behavior instead of the current «block event and update url» mechanism.
- knallfrosch 3y agoJavaScript:void(0)
- chrismorgan 3y agoI have reached this resolution: <a href="javascript:void(0)"> is never acceptable. If you have no reasonable value for an href, then you shouldn’t use an <a href> element, but probably a <button>. As for <a href="#">, it’s in the same boat, with the sole exception of jumping to the top of the page.
- chrismorgan 3y agoAnd the only way to achieve this is by having the mouse interact with an actual link element (HTML <a>, HTML <area> or SVG <a>) with a meaningful href. A few times I’ve encountered sites trying to be clever and detect Ctrl+click or middle-click and use window.open(), but this doesn’t behave natively: natively, middle-click or Ctrl+click probably open in a background tab, but open() opens a foreground tab, which will always be disruptive for people that use this stuff much, and sometimes infuriating. This isn’t the only reason for having real links; there are also things like status bar text on hover, and context menu on right click or long press, which may include options like Open Link in New Private Window that cannot be emulated in any way. If you want to intercepting link click events, you must check if the click is modified in some way like this: if (event.button || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return; Note that middle-click fires an auxclick event instead of click, and right-click fires contextmenu first and then auxclick if that’s preventDefaulted.
- ziml77 3y agoMaybe this should be supported by browsers though. The main place where I hate not having modals is when filling out forms and checking for a slightly expanded explanation about what is expected to be filled into a field. What would be the best behavior for those is if a click showed something inline and middle click (or right click -> open in new tab) opened a new page with the correct tab focus behavior.
- chrismorgan 3y agoThis is what can be accomplished by the is-click-modified code I listed. If the click is modified, let the event go through and the browser do whatever with it, but if it’s not modified, call event.preventDefault() to block navigation, then do what you want with it.
- jonwinstanley 3y agoI remember these days. Unfortunately I’ve not had a middle mouse button for a lot of years
- slig 3y agoWhen I was on a mac, CMD + Click worked fine.
- cypress66 3y agoIt's insane that this has been broken in Twitter for so many years (when trying to open a tweet).