1

I'm trying to to load facebook auth page for users to connect their fb accounts with my site. The problem is it's a different domain. Code is as below

var left = (screen.width/2)-(550/2);
    var top = (screen.height/2)-(250/2);
    fbPopUp = window.open(authorizeURL,'fbWindow','menubar=0,status=0,titlebar=0,toolbar=0,resizable=1,width=400,height=275, top='+top+' , left='+left);

How do I find out whether this window actually opened or not? I tried solution of Detect blocked popup in Chrome

Community
  • 1
  • 1
Shwetanka
  • 4,976
  • 11
  • 44
  • 68
  • possible duplicate of [Detect blocked popup in Chrome](http://stackoverflow.com/questions/668286/detect-blocked-popup-in-chrome) –  Jul 25 '13 at 15:53

5 Answers5

7

Basically there's a bug in Chrome. Although it hides the popup, it still executes and you still get the window object back - so regular checks don't work.

Here's the solution that worked for me:

var popup = window.open(url);

if (popup) {
  popup.onload = function () {
    console.log(popup.innerHeight > 0 ? 'open' : 'blocked');
  }
} else {
  console.log('blocked');
}

Working example here: http://jsbin.com/uticev/3/

Remy Sharp
  • 4,520
  • 3
  • 23
  • 40
  • 2
    This has apparently broken in newer versions of Chome. Doesn't work for me in "19.0.1084.52 m" at least – AHM May 30 '12 at 15:54
6

I was searching and searching, and finally found this, so I had to share, becuase like other people said it is broken in newer versions of chrome. So the fixed solution is this:

var popUp = window.open( url );
setTimeout( function() {
   if ( popUp.outerHeight === 0 ) {   
      alert('blocked'); 
   }
}, 25);
javajoe316
  • 151
  • 1
  • 2
  • 11
2

just modified Remy answer. This works for me.

        var win = window.open("", 'child','width=10,height=10,status=no,resizable=no');
        var objwin = new RegExp('object','gi');
        var isblock = false;

        if(objwin.test(String(win))) {
            if(typeof win.outerHeight ==="undefined" || parseInt(win.outerHeight)<10){
                isblock = true;
            }
            win.close();
        }else{
               isblock = true;
        }

        if(isblock){
          // do something here
        }
massquote
  • 4,387
  • 1
  • 14
  • 16
0

Simple:

var popup = window.open(host);
popup.onload = function (){
    if (!popup.innerHeight > 0){
        popup.close();
        // Popup blocked
    } else {
        // Popup enabled
    }
}
kaleazy
  • 5,922
  • 2
  • 47
  • 51
0

This solution works well for me:

loginWindow = window.open(url, '_blank', options);

setTimeout(function () {
    if (!loginWindow || loginWindow.closed || typeof loginWindow.closed == 'undefined' || parseInt(loginWindow.outerWidth) == 0) {
        alert('Turn off pop-up blocker and try again.');
    }
    else {
        loginWindow.focus();
    }
}, 500);
Leigh
  • 28,765
  • 10
  • 55
  • 103
oeddy
  • 35
  • 4