Popup blocker detection for all major browsers including Chrome....
Chrome popup blocker detection is a little different to others in that Chrome returns a valid window object after calling window.open, even with popups being disabled. There are a heap of posts around all basically stating that to determine whether this window object has been blocked by Chrome, we need to test whether the innerHeight of the popup has been set to 0.
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
var isPopupBlocked = function() { | |
var isBlocked, | |
popup = window.open('about:blank', 'popup_test','width=5, height=5, left=0, top=0'); | |
// pop under | |
if(popup) popup.blur(); | |
window.focus(); | |
isBlocked = !popup || typeof popup == 'undefined' || typeof popup.closed=='undefined' || popup.closed || popup.innerHeight == 0; | |
if(popup) popup.close(); | |
return isBlocked; | |
}; |
Chrome popup blocker detection is a little different to others in that Chrome returns a valid window object after calling window.open, even with popups being disabled. There are a heap of posts around all basically stating that to determine whether this window object has been blocked by Chrome, we need to test whether the innerHeight of the popup has been set to 0.
3 comments:
thanks.
Thanks a lot, good job !!!
Post a Comment