Firefox - website takes me to new tab automatically and I cannot stop it

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,150
Reaction score
10,490
So I have a website where I can select links and click a button to open them all at the same time. When I do that Firefox takes me to one of the newly opened links automatically.

I wanted to stop this behavior, so I looked and looked, and eventually found this option:

browser.tabs.loadDivertedInBackground

Now, when I set this to true, newly opened tabs never automatically take me to them. So if I click an ad on a site that normally opens in a new tab and takes me to it, now it doesn't happen. I also tried this code:

HTML:
<p><a href="#" onclick="[window.open](https://window.open)('[http://google.com](http://google.com)');

window.open('http://yahoo.com');">Click to open Google and Yahoo</a></p>

This code opens 2 links at the same time. I was thinking maybe opening multiple links at the same time somehow overrides Firefox. But no, the links opened and I was not automatically taken to any of the new tabs.

Also must be said that I'm having this problem in Firefox 75 and 74. But when I try it in Firefox 55.0.2, I don't have the problem. In Firefox 55.0.2 the "browser.tabs.loadDivertedInBackground" actually works even on the website where I have the problem (I can't share the site because it's behind login).

This appears to be the code responsible to open multiple links on the website I have an issue with:

https://pastebin.com/EyqrDtRy

So I tried everything I could think of. Many changes to the about:config, restarting my browser, unticking the "When you open a link in a new tab, switch to it immediately" option in Firefox. But nothing works. When I open links from this one site using this specific button, I always get automatically taken to one of the newly opened tabs.

Here is a similar-ish problem - https://www.reddit.com/r/firefox/comments/bnu6qq/opening_new_tab_problem/

Any ideas why this happens and how to fix it? I mean, a website shouldn't be able or allowed to override Firefoxe's native setting, right?
 
Does it happen in other browsers or just firefox?
 
Does it happen in other browsers or just firefox?

I tried it in Chrome, and it took me to one of the newly opened tabs.

But in Firefox 55.0.2 (after I changed that setting - browser.tabs.loadDivertedInBackground) it did not.
 
So the problem is solved. Here is how it went. And by the way, this is what happens when you pay $20 for a job versus, I don't know, $100 :p

The guy that did the work for me basically told me that he did all he could, it's a browser issue not a code issue. But I've been alive long enough to know that experts schmexperts :p

So on the reddit thread I referenced in my OP, I read this:

But for some reason, on certain sites, when I use the middle mouse button I first get the message saying Firefox has prevented a popup, and it keeps blocking me from using the wheel to open the tab until I allow it. Then it starts opening the tab (not a popup) and forces the switch to that newly opened tab even though the setting is still disabled.

And this:

As for why the popup blocker is being triggered, normally the click event is exempt from blocking. Some sites don't call window.open() immediately but only after doing something else, and that may cause Firefox not to apply the exemption. Or possibly your exemption list has been altered?

That got me thinking, the button that I had a problem with also would trigger a popup warning, but only the first time I use it on a new browser. After I "Allow" it on Firefox, then the popup warning doesn't appear again. Good thing I installed and uninstalled Firefox like 20 times yesterday, so I really go to see this happen over and over again.

And then the guy says that "Some sites don't call window.open() immediately but only after doing something else", which got me thinking... yesterday I was trying to get some javascript to work for a bookmarklet, and the guy that helped me out said it should work, but I was having a weird problem, coincidentally also on latest version of Firefox (but not on older version of Firefox). The guy told me he doesn't know why I'm having the problem (experts schmexperts). But then I looked at some other bookmarklets I had, and I remembered one where I had a similar issue. And then I remembered that the code that worked had a "setTimeout(()" on it, while the non-working code did not.

So I kept on reading, and I ran into this - https://javascript.info/popup-windows

And it says:

What if the popup opens from onclick, but after setTimeout? That’s a bit tricky.

Try this code:

// open after 3 seconds
setTimeout(() => window.open('http://google.com'), 3000);
The popup opens in Chrome, but gets blocked in Firefox.

…If we decrease the delay, the popup works in Firefox too:

// open after 1 seconds
setTimeout(() => window.open('http://google.com'), 1000);
The difference is that Firefox treats a timeout of 2000ms or less are acceptable, but after it – removes the “trust”, assuming that now it’s “outside of the user action”. So the first one is blocked, and the second one is not.

So that got me thinking, you don't say? "The difference is that Firefox treats a timeout of 2000ms or less are acceptable"

So anyway, at this point I really have no idea what's going on with the world, didn't even get to have coffee. But I ask the guy that did this work for me to add a timeout delay to the code. He tells me this will not make it faster, but slower. I say, well, goddamn it exactly!!! That's not what I said, but I said yes okay do it. He told me because he created something that works already, this is the last edit he is doing for me (note to self: don't hire guy again).

So he did it, and it worked!

Why do I have to solve all the problems around here? Hm? Okay gogol and larry igna and ivexss and there's other dudes that solve problem, but I mean come on, for you guys that work with shit that has to do with browser compatibility, how about you get fucking updated and be aware of things? I don't need a solution that will work for Firefox version 5 years ago, you know? Damn...

 
Oh and just to add. For anyone that may run into a similar trippy trippy trip as I did here, the solution also involves going into Firefox in "about:config" and changing this code to True.

browser.tabs.loadDivertedInBackground

Cheers :)

All right let's cheer up around mhya :D

 
Back
Top