external link icon#59
Conversation
| if (a.href.startsWith(window.location.origin)) return; | ||
| a.classList.add('external-link'); | ||
| a.setAttribute('target', '_blank'); | ||
| a.setAttribute('rel', 'noopener noreferrer'); |
There was a problem hiding this comment.
noreferrer prevents some forms of analytics, but is only really warranted for secure pages with secrets in the URL, i.e. not relevant here. It also implies noopener, and some older browser do not handle both being specified.
noopener is implied by target=_blank, so the whole thing can be removed.
| if (a.protocol !== 'http:' && a.protocol !== 'https:') return; | ||
| if (a.href.startsWith(window.location.origin)) return; | ||
| a.classList.add('external-link'); | ||
| a.setAttribute('target', '_blank'); |
There was a problem hiding this comment.
Don't set target=_blank unless you want to annoy people. If people want to open the link in a new window, then their browser gives them the option, usually via Ctrl+click or similar. But if we set this, then they have no option to open the link in the current window.
Seriously, it is both bad for accessibility and doesn't achieve its goal; best practice is to not do this.
| if (a.classList.contains('external-link')) return; | ||
| if (a.protocol !== 'http:' && a.protocol !== 'https:') return; | ||
| if (a.href.startsWith(window.location.origin)) return; | ||
| a.classList.add('external-link'); |
There was a problem hiding this comment.
Why use awkward JS when simple CSS suffices‽ People might even have JS switched off.
Just make the selector be a:[href^="http"]:not([href^="https://docs.dyalog.com/"]:not([href^="https://dyalog.github.io/documentation/"])
There was a problem hiding this comment.
I thought about this and wanted to avoid it not showing up on local previews and having to document (where?) that external links show in the built site but not local previews. But maybe we can add also ^http://localhost. I'll try it.
Addresses #54. Close only after related Dyalog/documentation#820 is completed