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
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
Share Improve this question edited May 23, 2017 at 12:08 CommunityBot 11 silver badge asked Jan 10, 2012 at 11:17 ShwetankaShwetanka 5,03611 gold badges45 silver badges68 bronze badges 1- possible duplicate of Detect blocked popup in Chrome – user456814 Commented Jul 25, 2013 at 15:53
5 Answers
Reset to default 7Basically 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./uticev/3/
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);
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
}
Simple:
var popup = window.open(host);
popup.onload = function (){
if (!popup.innerHeight > 0){
popup.close();
// Popup blocked
} else {
// Popup enabled
}
}
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);