Interfering with opening in new tabs

Internet

I make regular use of command/control while clicking links to open target pages in new browser tabs. You probably do too! It’s especially useful when browsing search result pages, so you’re not constantly flicking between each result and the original search. This is established, expected behaviour… so naturally, JavaScript to the rescue!

There are certain sites that prevent you opening a new tab when clicking a link, either due to a deliberate design decision, or as a side-effect of poorly-written code. Both of these are bad design for accessibility, and for me wanting to shop on your site.

Here’s an example where I saw a site using an event handler to redirect people to the correct product page:

<a href="$PRODUCT" class="js-gtm-push-event-with-callback"
data-gtm-push-event="{"event":"productClick","ecommerce":{"click":{"actionField":{"list":""}},"products":{"name":"$PRODUCT","id":"$ID"}}}">$PRODUCT</a>

Despite having the target page in the href attribute as a link is supposed to, the JavaScript kicks in upon clicking it. This prevents the new tab request.

I’m leaning towards using NoScript full time again. It breaks so many sites, but counter-intuitively it breaks others into working again. Isn’t that the modern web in a nutshell?

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

You can leave me a comment by contacting me, and I might publish your thoughts. Please read the FAQs first though.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!