How do you make middle click NOT open a new tab (so I can avoid it)
I notice this a lot on health insurance search results: you search for a doctor and get a list of cards back. I want to be able to middle click each card that seems interesting then look at the details on a second pass. On most websites, this middle a new tab but on these websites it has no effect; the only option is to click one card at a time, changing the entire page, and if it isn't what I was looking for, the back button usually doesn't function correctly and I have to reenter the search.
How do you build this behavior? I'm only asking because I want to figure out how I can turn it off with a user script.
If the answer is, "it depends on the site," here's a specific example: https://www.techjobsforgood.com/jobs/?job_function=Engineering
If you middle click anywhere on the card besides the "View Job," it has no affect. But a left click changes the entire page. What is causing this?
Tech Jobs for Good
Use Tech Jobs for Good to find tech jobs at mission driven companies and nonprofits working on pressing social and environmental issues.
8 Replies
the most common way is probably to not use anchor tags, but use javascript for navigation. Alternatively, you could listen to the
middleclick
event and use event.preventDefault()
either way, it's a terrible idea
taking functionality away from the end user is unfriendly at the best of times, and an a11y nightmare at worsedo you have any advice on "undoing the damage" when you are not the developer? e.g., with a userscript
User scripts are really going to be a site by site thing
I figured. Are in-depth questions about user scripts off topic here?
It's not a common topic, but feel free to ask. I'd suggest making a new thread and make sure to be very clear it's a userscript question. Maybe even include a sentence about what that is, a lot of people might not be super familiar
Here in #front-end would be best
Here's a starting point for you @bawdyinkslinger
node.getAttribute("onclick").split("'")[1]
gets the location.href='...'
and splits it at the '
, then grabs the index 1 item which is the url you want.
window.open(url, "_blank")
will open the given url in a new tab
the document and node stuff iterates through all occurences of the card, and modifies the onclick
attribute from setting the location.href
into opening a new tab with the urlGreat! Thanks. I have another user script question I'll ask in another post