News for hackers. Stuff that matters.
Re:Links are not buttons (2013) by superkuh on Friday April 09, 2021 @01:37PM (#26753513)
Everything is a button now that javascript applications have replaced HTML documents. And there are no such things as anchors or links anymore. They are not URLs but instead triggers for more javascript execution. We're, unfortunately, well past this minor problem and onto much more serious ones that eclipse it.
Re:Links are not buttons (2013) by anchpop on Friday April 09, 2021 @02:14PM (#26753962)
The FUD about SPAs and Javascript on HN is insane. Here's my personal site: https://chadnauseam.com/. It's a SPA. It loads fast. There are such things as anchors and link (inspect element if you like). They have URLs and you can ctrl-click to open in a new tab.

(The biggest proble with it is that I've been playing around with some js to animate a fade-in effect on page load, and it seems a little laggy and makes the site not work with javascript disabled. If I can't fix those issues I'll probably remove that in a few days.)

Re:Links are not buttons (2013) by bestinterest on Friday April 09, 2021 @03:11PM (#26754777)
I'm not sure its FUD, your main page takes 63.5KB + 38.7KB for the gatsby reactified framework? + an extra 39.8KB in some js bundle and another 51.7KB in some other js bundle.

Also you end up thrashing 5MB of browser storage when I hovered a link check out Application -> Storage in Chrome.

Maybe I'm crazy but your page should not need that much, your site is making 20 requests to resources (thankfully you have http2) and the longest request took about 7s on a slow 3g connection. For comparison here is Tom MacWright's page https://macwright.com/ which does 2 requests at 14kB total taking 2.3s on a slow 3g connection.

I will give you the prefetch trick is superslick in the Gatsby framework for blogs but no reason to have a whole React framework around it. Just use https://instant.page/

I say all this and I do love the component nature of React and SPA's (I love Svelte the most at the moment) but it does really not feel like the right tool for 99% of personal blogs.

Re:Links are not buttons (2013) by bobbylarrybobby on Friday April 09, 2021 @02:44PM (#26754399)
When I hover over most links on your page, I see the link URL in the bottom left corner of the browser window. But when I hover over the discord and twitter buttons, I don't. And when I command-click those buttons they don't open in a new tab.

So you used buttons (spans?) instead of links and broke the very functionality the article talked about.

Re:Links are not buttons (2013) by throwaway8581 on Friday April 09, 2021 @03:20PM (#26754879)
>And when I command-click those buttons they don't open in a new tab.

One of my greatest annoyances. I’m an open in new tab guy. When I see this annoying pattern I end up clicking, middle clicking the back button (only possible on desktop), then switching the tab positions, so I can get the correct outcome.

Re:Links are not buttons (2013) by a1369209993 on Friday April 09, 2021 @04:05PM (#26755402)
> middle clicking the back button

TIL, apparently. Also, middle-clicking refresh opens a new copy of the current page. So much for GUIs being discoverable. Thanks.

Re:Links are not buttons (2013) by runarberg on Friday April 09, 2021 @04:54PM (#26756023)
To be fair, your browser probably has a history menu option in the top menu that opens a sidebar with your recent history. You can probably right click the top page and click “open in a new tab”. This is highly discoverable and does the same thing (just in more steps). You can also select the text in your URL bar, right click and copy, then open a new tab the usual way and paste the URL there. Also the same results but highly discoverable with extra steps.

As far as I know highly discoverable means there is no hidden functionality, not that every shortcut is advertised.

Re:Links are not buttons (2013) by tacotime on Friday April 09, 2021 @05:02PM (#26756122)
I’m a regular laptop user and I often use this trick. In Windows you can ctrl+click the back button to pop open a tab for the previous url, I’d guess command+clicking the back button does the same on a Mac.
Re:Links are not buttons (2013) by throwaway8581 on Friday April 09, 2021 @05:38PM (#26756534)
Thanks. I didn’t know that. I usually just map three finger tap to middle click.
Re:Links are not buttons (2013) by Ashanmaril on Friday April 09, 2021 @02:42PM (#26754358)
The Discord/Twitter "buttons" on your site actually highlight one of the issues here. You can't open them in a new tab, or hover to see where they're taking you. They also don't make the mouse react properly to being on something clickable (though that could be fixed with a `cursor: pointer` style)
Re:Links are not buttons (2013) by tshaddox on Friday April 09, 2021 @03:03PM (#26754658)
Which is actually a clear illustration of the point: that you have to go out of your way to make "link-like" things that aren't actual links. Clearly whatever framework or rendering library the site is using supports client-side navigation via real working anchor tags. But for some reason, they decided to not use those for the social media widgets.
Re:Links are not buttons (2013) by frosted-flakes on Friday April 09, 2021 @08:58PM (#26757966)
Historically, only links got the pointer (hand) cursor, not all clickable things. Buttons and everything else kept the regular arrow cursor. Desktop software on all operating systems has always worked like this.

However, this convention has been muddied a lot on the Web in the past few years, but I still like to follow it.

Re:Links are not buttons (2013) by dmitriid on Friday April 09, 2021 @06:39PM (#26757094)
This is a page that displays nothing but static text.

- It does 71 requests

- It loads 2 MB or resources for this static page

- Saves at least 6.7 MB of data in storage on load, no idea where that comes from (service workers maybe?). It jumps to ~16 MB on page refresh

- Running Lighthouse on your website gives 2.9s until first contentful paint. 3 seconds to display less than a kilobyte of text. And that's for the front page. It's significantly worse for longer pages.

- And on top of that it has buttons-for-links for discord and twitter (that are also, funnily enough, removed by ad blockers like AdGuard)

Oh yeah, I see how the "FUD about SPAs" is in reality fully justified criticism.

Re:Links are not buttons (2013) by coldpie on Friday April 09, 2021 @03:29PM (#26754979)
> The biggest proble with it is that I've been playing around with some js to animate a fade-in effect on page load

Yeah, there's no reason do this. It's text. Just let it render. KISS.

Re:Links are not buttons (2013) by boring_twenties on Friday April 09, 2021 @06:41PM (#26757108)
It certainly loads fast -- in fact, I get the completely blank page pretty much instantly.

I do appreciate that it's at least a black blank page and not a bright white one, though.

Re:Links are not buttons (2013) by jraph on Friday April 09, 2021 @04:06PM (#26755413)
It's a blank page for me. It does not load at all.

I want my browser to display documents, not to run code. I don't want documents to be apps. The browser already has very sophisticated code to render documents well.

Unless I am really running an app - then this is somewhat fine to use the browser as a runtime. I'll make sure to only run open source apps with it, unless I really don't have a choice.

edit: wait, your page is so close to render perfectly without JS! You can fix this by avoiding opacity:0 in the HTML!

Re:Links are not buttons (2013) by Isognoviastoma on Friday April 09, 2021 @03:27PM (#26754961)
This is great example of what is wrong with many SPAs. They should not be applications in first place. Why is it using tons of JS to display few paragraphs of static text? It could be hosted as static html pages. It also kind-of works in lynx, but totally don't in FF without JS.
Re:Links are not buttons (2013) by cookiengineer on Friday April 09, 2021 @05:30PM (#26756444)
I'm not sure you are aware that everybody that activates JS just to see this type of content (which can be done in a static html only manner) will be heavily disappointed when they've loaded your page.

It's like waiting to load a WebGL demo of a damn teapot. Afterwards you have a negative impression, such as me now thinking of chadnauseam, that I now think has no effing clue about webdev if this person can't create two damn paragraphs without a JS framework.

If you throw a heavy JS framework on a website, make sure the content is at least as heavy. If the content is two paragraphs of text, why would you disappoint users so much when they visit from mobile?

Re:Links are not buttons (2013) by frosted-flakes on Friday April 09, 2021 @09:08PM (#26758023)
Gatsby actually works extremely well for no-JS users. It is a static site generator, after all, that serves you raw HTML with a secondary JS payload. It's just that the author broke his website by setting the opacity to 0 on load so he could do a fade-in effect with JavaScript, even though there are much easier ways to do that in CSS. All the text is still there, just invisible.
Re:Links are not buttons (2013) by minitech on Friday April 09, 2021 @06:40PM (#26757104)
> It's a SPA.

Yeah, but even ignoring all the SPA-caused bugs that other people pointed out – why? It’s just static content.

Re:Links are not buttons (2013) by bobthepanda on Friday April 09, 2021 @02:38PM (#26754299)
Couldn’t you just do fade in with CSS?
Re:Links are not buttons (2013) by boring_twenties on Friday April 09, 2021 @10:45PM (#26758509)
Hm, wait a minute. I'm not a webdev by any stretch, so I could be talking out of my ass here. But, couldn't you "fix" the issue by leaving the opacity alone in the HTML, and setting it to 0 in the beginning of the JavaScript?
Re:Links are not buttons (2013) by NathanielK on Friday April 09, 2021 @08:28PM (#26757815)
Your site is broken on some browsers that do not support darkmode. On Firefox 78.9 ESR the text is #EBEBEB on #FFFFFF, so it's illegible. Firefox 78 ESR is supported till September this year.
Re:Links are not buttons (2013) by chociej on Friday April 09, 2021 @01:47PM (#26753633)
TBH I don't care too much what someone does with a button or link, but if hold Ctrl and it doesn't open in a new tab, I'm gonna be grumpy.
Re:Links are not buttons (2013) by jibbit on Friday April 09, 2021 @02:41PM (#26754341)
Twitter seems to have recently (partially) given up on <a> tags, meaning i can no longer right-click to open in a new tab - it is infuriating
Re:Links are not buttons (2013) by anthk on Friday April 09, 2021 @02:44PM (#26754392)
Re:Links are not buttons (2013) by dredmorbius on Friday April 09, 2021 @03:24PM (#26754914)
Chronically rate-limited, use an alternative.

(I could mention one that works, but that will eventually of course just compound the problem. So my secret fishing spot remains secret ;-)

Re:Links are not buttons (2013) by blewboarwastake on Friday April 09, 2021 @04:16PM (#26755535)
You can use this extension: https://github.com/SimonBrazell/privacy-redirect and use the "use a random instance" option
Re:Links are not buttons (2013) by dredmorbius on Saturday April 10, 2021 @02:13AM (#26759351)
Thanks, useful.
Re:Links are not buttons (2013) by thitcanh on Friday April 09, 2021 @10:00PM (#26758301)
So you do care since only links follow your browsers’ behavior. Nothing else can be right-clicked to show “Copy link address” in the dropdown for example.

The golden rule is that if a button opens a link to a page that has its own URL, it should be a plain anchor tag.

You can apply whatever JavaScript on top of it to “ajaxify” it, as long as you ignore altered clicks (ctrl, cmd, shift, etc)

Re:Links are not buttons (2013) by Kelamir on Friday April 09, 2021 @01:53PM (#26753706)
Hold control to open links in new tabs?! Woah! That's so much better than using middle mouse button, which is just suffering. Thanks chociej :)
Re:Links are not buttons (2013) by kaibee on Friday April 09, 2021 @01:58PM (#26753774)
I have one of those fancy gamer mice (Logitech G700S) and I bound the most prominent thumb button to middle-click. Haven't looked backed, making scroll-wheels clickable was a mistake.
Re:Links are not buttons (2013) by hypertele-Xii on Friday April 09, 2021 @02:48PM (#26754460)
Scroll wheels themselves are a bad implementation of a good idea. I bought a cheap USB volume control knob and used AutoHotKey to rebind volume up/down events into wheel scrolls. Productivity increased like crazy! Scrolling is no longer a chore, it's a pleasure. I even went the extra mile and coated it with rubber for a good grip.
Re:Links are not buttons (2013) by wussboy on Friday April 09, 2021 @03:41PM (#26755128)
I have always used Gesturefy to make right-click and drag down to open in a new tab. I don't know where I originally picked up this gesture...maybe Opera in 2003? But I've always loved it and use it a hundred times a day.
Re:Links are not buttons (2013) by Ashanmaril on Friday April 09, 2021 @02:46PM (#26754424)
Why is a 2-handed input better than a 1-finger input?
Re:Links are not buttons (2013) by marcosdumay on Friday April 09, 2021 @03:46PM (#26755194)
It certainly depends on your hardware. The GP is just rooted in a completely different experience than yours.
Re:Links are not buttons (2013) by ehnto on Friday April 09, 2021 @01:47PM (#26753646)
It's tricky to balance user expectations with semantic HTML now that the web has evolved so far.

The easiest example I have from my industry is a product card in a grid of products. There really is no correct spot to link it in some designs, but the user expects to click any part of the box and be taken to the product page. So you wrap the whole box in an anchor tag, which has its own host of problems.

As you said though, that is a bygone problem, this ship has sailed in the land of SPAs. Even a simple blog is an SPAs these days.

Re:Links are not buttons (2013) by ravenstine on Friday April 09, 2021 @02:07PM (#26753881)
User expectations, or executive expectations?

In my experience, the effective expectations of users are remarkably low. If you were to survey users, you'd get the impression that users are very particular. In reality, users tolerate all sorts of things that most of us on HN would consider primitive or nearly broken. If most web applications actually relied mostly on constructs provided by the browser/DOM rather than JavaScript, the average user wouldn't notice or care.

But there are product owners who power trip on the possibility that they too could be just like The Google, so they want everything to be unnecessarily animated and dynamic. On top of that, many of them want Silicon Valley programming at San Fernando Valley prices, so not only do they request that their web applications be unnecessarily complicated, but the junior devs they hire are given no direction and the code gets bloated, wrecking performance (which matters more than "delightful" UIs).

Re:Links are not buttons (2013) by ehnto on Friday April 09, 2021 @02:50PM (#26754480)
I am entirely inclined to agree with you. It is definitely perpetuated by project stakeholders, even developers wanting to try new tech.

But now that we have spent years training eCommerce user behaviours you do find that people will be busy clicking everything but the product title, arguably the most semantic place to put the anchor, so it may take a user a few goes to get where they're going. The user might not care but many of the project stakeholders do.

While I am an evangelist of a utilitarian, semantic web, I feel it's an idealism that hasn't survived it's encounter with the real world in commercial software. We went from being worried about javascript image sliders being too heavy, to making the client compute and render the entire application, in about 8 years. I think the trajectory is clear, and I doubt we'll have a watershed moment where the whole tree of stakeholders suddenly wants less.

Re:Links are not buttons (2013) by pjerem on Saturday April 10, 2021 @02:42AM (#26759478)
If this particular thing of clicking everything but the title is really a thing, nothing is blocking you to add some minimal JavaScript which « onclick » on the item div element, triggers a click on the link. Add some « cursor: pointer » in you Stylesheet and you are done.

It’s literally 2 loc, it doesn’t affect accessibility and it’s using JavaScript for what it was meant : adding some optional convenience.

I realize I’ve not done real server rendered sites for years, but adding good old « optional convenience » JS without jQuery and broken browsers, but with ES6, modules, and maybe WebComponents would probably be a really pleasant experience.

Re:Links are not buttons (2013) by ehnto on Saturday April 10, 2021 @03:43AM (#26759730)
Yes you are right, that's a good approach. Another commenter linked a great article on accessibility and "card" style content which also recommended that approach, worth a read as it discusses a lot of the caveats and your approach tackles the majority of the issues you can encounter.
Re:Links are not buttons (2013) by dmitriid on Friday April 09, 2021 @06:42PM (#26757117)
Re:Links are not buttons (2013) by extra88 on Saturday April 10, 2021 @10:02AM (#26761546)
Yes. Here’s an article that builds on this:

https://css-tricks.com/block-links-the-search-for-a-perfect-...

Re:Links are not buttons (2013) by ehnto on Saturday April 10, 2021 @01:22AM (#26759133)
That's a great exploration of the issues involved. Thanks for the link!
Re:Links are not buttons (2013) by marcosdumay on Friday April 09, 2021 @03:52PM (#26755261)
> So you wrap the whole box in an anchor tag, which has its own host of problems.

Looks like the correct solution to me. What are the problems?

Re:Links are not buttons (2013) by guntars on Friday April 09, 2021 @04:26PM (#26755660)
You can't have interactive elements inside anchor tags. Very often the box will have some additional buttons for different actions, like "Save for later". I like the approach of using an anchor tag just for the title and have another click handler on the box to serve as a fallback, but you don't get to ctrl-click on the box anymore. Alternatively you can have the link be a sibling of the buttons in the DOM, but visually cover the whole box and appear behind the buttons. As you can imagine, any solution like this is going to add more work and be a potential source for bugs.

This is one of the two things that I really wish browsers would fix, instead of cramming in completely new features. The second is how hard is it to make popovers work correctly, especially inside scrollable containers.

Re:Links are not buttons (2013) by stevula on Friday April 09, 2021 @07:05PM (#26757276)
Cant you just use event.stopPropagation on the inner button’s event handler to stop the browser from following the link? Of course this requires JS but I assume you’re using Js if you have custom buttons.
Re:Links are not buttons (2013) by ehnto on Saturday April 10, 2021 @01:18AM (#26759118)
You can, but you can also see how it isn't an elegant solution. What if the user has javascript disabled? Do you also have to capture the click for the space around the interactive spots so a misclick into whitespace doesn't click the link?

It is what is normally done but it isn't perfect.

Re:Links are not buttons (2013) by stevula on Saturday April 10, 2021 @03:48AM (#26759749)
The post I was replying to was specifically lamenting the inability to have interactive elements inside of anchor tags, which I think is solved by event.stopPropagation. If you have a button in an anchor tag and it's not a submit button, you need JS for the button to work anyways.
Re:Links are not buttons (2013) by marcosdumay on Friday April 09, 2021 @04:38PM (#26755827)
Oh, that's a problem.

That really looks like a task for image maps, except that they only work for images. Yeah, I agree with those two problems.

Re:Links are not buttons (2013) by ehnto on Saturday April 10, 2021 @03:46AM (#26759739)
Sites breaking "ctrl+click" or open in a new tab shortcuts are the worst. Even JIRA does it on text ticket links, and it's a power user focused tool. Very frustrating.
Re:Links are not buttons (2013) by anhanhanh on Friday April 09, 2021 @01:47PM (#26753638)
That's just not true. Well known and widely used libs such react-router are an evidence of that.
Re:Links are not buttons (2013) by lunfard00 on Friday April 09, 2021 @02:03PM (#26753831)
In 2013 most people were happy with every new shiny app, and now that web is looking more and more like an app, is that an issue?
Re:Links are not buttons (2013) by robertoandred on Friday April 09, 2021 @04:46PM (#26755927)
You're not understanding the semantic and UX reasoning behind this article. JavaScript has no relevance to it at all.