1

I'm aware that FF4 doesn't allow the use of window.blur() unless "Raise or lower window" setting is enabled in the FF configuration. It simple ignores the event.

I'm aware that some site still manage to open a pop-up window and keep focus on your current window, even when this setting is switched off. How do they achieve this?

Additionally, I don't understand why .blur() and .focus() doesn't work when both pages reside on the same domain. According to http://support.mozilla.com/en-US/questions/806756#answer-167267 this should work.

  • Can you give us an example of the site that you saw ? it might not be a pop-up in the traditional sense - might well be a div within the page that looks like a pop-up – Manse Nov 03 '11 at 14:11
  • Hi, PirateBay does it as soon as you click on any of their links. –  Nov 03 '11 at 14:14
  • Why support so old browser? Current Fx version is 8. – Wojciech Bednarski Nov 09 '11 at 01:33
  • It's a requirement, not everybody updates to the newest version as soon as it comes out. –  Nov 10 '11 at 11:46

2 Answers2

6

This works for me in Firefox and Chrome, in default settings (JSFiddle):

function popUnder(url, width, height) {
    var popUnderWin, nav = navigator.userAgent,
        isGecko = /rv:[2-9]/.exec(nav),
        hackString;

    hackString = nav.indexOf('Chrome') > -1 ? "scrollbar=yes" : "toolbar=0,statusbar=1,resizable=1,scrollbars=0,menubar=0,location=1,directories=0";

    popUnderWin = window.open("about:blank", "title", hackString + ",height=" + height + ",width=" + width);

    if (isGecko) {
        popUnderWin.window.open("about:blank").close();
    }

    popUnderWin.document.location.href = url;

    setTimeout(window.focus);
    window.focus();
    popUnderWin.blur();
}

document.getElementById("asd").addEventListener("click", function() {
    popUnder("http://www.google.com", 1024, 768);
}, false);
<div id="asd">click here</div>

I didn't manage to get it work without the hacky extra parameters to window.open, so there is something to them.

hichris123
  • 10,145
  • 15
  • 56
  • 70
Esailija
  • 138,174
  • 23
  • 272
  • 326
3

http://support.mozilla.com/en-US/questions/806756#answer-167267

They say that it isn't possible unless everybody goes to about:config and sets dom.disable_window_flip to false.

I am not aware of any code that bypasses this restriction but I think the other websites use something other than window.blur() and window.focus()

There is a similar article here

Community
  • 1
  • 1
Anish Gupta
  • 2,218
  • 2
  • 23
  • 37
  • Hi, thank you for your reply. As I have said in the question, I'm aware of the restriction, but at the same time I'm aware of a number of sites that can achieve this. Their javascript is encrypted and I'm unable to have a look how they do it. –  Nov 10 '11 at 11:47
  • @PointedEars He said in the question The Pirate Bay. I can't visit it since my ISP has blocked it. – Anish Gupta Nov 28 '11 at 15:47