3 ms·
I think the converse—buttons are not links—doesn't get enough attention. The litmus test is that if clicking it is supposed to navigate, you should also be able
by _greim_ 6y ago
I think the converse—buttons are not links—doesn't get enough attention. The litmus test is that if clicking it is supposed to navigate, you should also be able to shift+click or middle-click to open it in a new tab, or drag it up to your toolbar to make a bookmark.
- thitcanh 6y ago<button> is not commonly mis-used as a link. I do agree that <div onclick="goTo('/contacts')"> and its equivalents are too damn common and just show complete lack of knowledge of the platform. <a> is the core element of the World Wide Web, without which there wouldn’t be a web.
- pottertheotter 6y agoI don't know what it is that people do that breaks being able to open a link in a new tab, but there's little I hate more than that. Especially on an ecommerce site where I'm likely to open several products in a separate tab. Some break middle clicking but I can still right click and select "open in new tab" from the menu. But there's others that don't even allow that. It's awful.
- jspash 6y agoI was recently required to add some JS to our product links from the search results pages. It’s a click-jacking script that sends tracking data to Google Analytics. There is a callback that fires when GA is happy that it got the goods. When that signal arrives, we then forward the user to where they wanted to go. The entire thing makes me feel dirty. The data collected is never even looked at. And yes, it breaks middle-click and right-click behaviour. Anyone hiring Rails devs anymore? ;)
- sfvisser 6y agoMany single-page-apps, and unfortunately also many regular looking pages, fetch new content using Ajax and splice it in the page dynamically. This has some obvious advantages for some use cases: preserving local state, fast refresh, less duplicate data fetching from the server, etc Downside is those are not links and opening in a new tab doesn’t work by default. It’s fixable in most cases, but additional work. Luckily modern frameworks like Next.js make it easy to build apps and pages that have best of both worlds.
- XCSme 6y agoIt's easy: you can use React Router and push a new route/URL when the link is clicked with onClick. This breaks middle/right clicks. I actually did this mistake when starting with React, now I try to make everything as close to a native link as possible.
- dragonwriter 6y ago> Some break middle clicking but I can still right click and select "open in new tab" from the menu IIRC, that’s a very old (long since fixed, but not everyone updates) bug in React Router’s Link component.