When a user clicks a link in my application, I need to "enrich" the clicked URL with some additional context (depending on the interaction) and then proceed as normal.
"As normal" means to set the window location to the new URL, or to open a new tab if a meta key is held while clicking.
This works as expected in all modern browsers except Firefox; in Firefox, the tab is always focused, regardless of what's set in Preferences > Tabs > "When I open a link in a new tab, switch to it immediately".
I can't just let the MouseEvent
through, because I need to direct to a different URL than that on the clicked <a href>
; I have to stop propagation of the click event.
In short, how can I get window.open('url', '_blank')
to respect the user's preferences and any meta keys in Firefox?
EDIT: My question differs from Open a new tab in the background? in that my need is for Firefox to work like other browsers; Chrome is working fine here. Also, I don't want the target page to always open in the background, I want it to open in another tab on a ctrl+click/cmd+click/middle-mouse click, or in the current window on a non-meta click, and to respect user prefs for opening focused or in the background. Updated the title to address this.