Created
August 1, 2014 12:51
-
-
Save dimorphic/310018cfd9abe385bbec to your computer and use it in GitHub Desktop.
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
function checkPopupBlocked(poppedWindow) { | |
setTimeout(function(){doCheckPopupBlocked(poppedWindow);}, 5000); | |
} | |
function doCheckPopupBlocked(poppedWindow) { | |
var result = false; | |
try { | |
if (typeof poppedWindow == 'undefined') { | |
// Safari with popup blocker... leaves the popup window handle undefined | |
result = true; | |
} | |
else if (poppedWindow && poppedWindow.closed) { | |
// This happens if the user opens and closes the client window... | |
// Confusing because the handle is still available, but it's in a "closed" state. | |
// We're not saying that the window is not being blocked, we're just saying | |
// that the window has been closed before the test could be run. | |
result = false; | |
} | |
else if (poppedWindow && poppedWindow.outerWidth == 0) { | |
// This is usually Chrome's doing. The outerWidth (and most other size/location info) | |
// will be left at 0, EVEN THOUGH the contents of the popup will exist (including the | |
// test function we check for next). The outerWidth starts as 0, so a sufficient delay | |
// after attempting to pop is needed. | |
result = true; | |
} | |
else if (poppedWindow && poppedWindow.test) { | |
// This is the actual test. The client window should be fine. | |
result = false; | |
} | |
else { | |
// Else we'll assume the window is not OK | |
result = true; | |
} | |
} catch (err) { | |
//if (console) { | |
// console.warn("Could not access popup window", err); | |
//} | |
} | |
if(result) | |
alert("The popup was blocked. You must allow popups to use this site."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
var popup=window.open('location',etc...);
checkPopupBlocked(popup);