Created
August 28, 2014 23:47
-
-
Save pospi/91ce87e0f64048780251 to your computer and use it in GitHub Desktop.
Detect blocked popup windows in all browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.isPopupBlocked = function(popup_window, cb) | |
{ | |
var CHROME_CHECK_TIME = 2000; // the only way to detect this in Chrome is to wait a bit and see if the window is present | |
function _is_popup_blocked(popup) | |
{ | |
return !popup.innerHeight; | |
} | |
if (popup_window) { | |
if (popup_window.closed) { | |
// opened OK but was closed before we checked | |
cb(false); | |
return; | |
} | |
if (/chrome/.test(navigator.userAgent.toLowerCase())) { | |
// wait a bit before testing the popup in chrome | |
setTimeout(function() { | |
cb(_is_popup_blocked(popup_window)); | |
}, CHROME_CHECK_TIME); | |
} else { | |
// for other browsers, add an onload event and check after that | |
popup_window.onload = function() { | |
cb(_is_popup_blocked(popup_window)); | |
}; | |
} | |
} else { | |
cb(true); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment