javascript - Chrome popup "blocker" loads hidden page & plugins - any way around this? -
if launch window flash game in it, , chrome's popup blocker suppresses it, user hears music game, sees nothing. because chrome doesn't block window; hides it.
chrome loads page favicon , page title, can display in popup blocker dialog (which see when clicking icon in address bar). don't close window. plugins run, scripts can call opener - it's regular window, invisible. (okay, malware developers, please stop drooling.)
chrome parse contents of <head> tag retrieve <title> , favicon <link/> tag without loading page. close hidden window after they've retrieved icon/title. show url instead of icon/title. instead, bug continues fester since 2008...
http://code.google.com/p/chromium/issues/detail?id=3477
http://code.google.com/p/chromium/issues/detail?id=38458
anyhow, question is: can detect when happens? perhaps there's in window.chrome javascript object indicate window in invisible state, can close or remove flash?
__
based on prusse's answer, here's ended with...
function ispopupzombie(popwindow, delay) { /// <summary>attempts detect zombie window "blocked" (hidden) chrome (v.8-12, maybe more)</summary> /// <param name="popwindow">the popup window object</param> /// <param name="delay">optional delay in ms; not necessary when called via other delayed event/function</param> if (window.chrome && typeof(popwindow) == 'object') { if (delay && !isnan(parseint(delay)) && delay > 0) { window.settimeout(function () { ispopupzombie(popwindow, 0); }, delay); } else if (typeof(popwindow.opener) == 'object') { var w = (popwindow.innerwidth && popwindow.innerwidth > 0) ? popwindow.innerwidth : popwindow.outerwidth; var h = (popwindow.innerheight && popwindow.innerheight > 0) ? popwindow.innerheight : popwindow.outerheight; //console.log('_ispopupzombie: ' + w + ' x ' + h); return (w === 0 && h === 0); } } return false; } function handlepopupzombie(zombiewindow, notify, callback) { /// <summary>tries close zombie or alert chrome fail</summary> /// <param name="zombiewindow">popup window object known hidden unblocked popup</param> /// <param name="notify">true notify user of hidden window, false close zombiewindow</param> /// <param name="callback">optional function call, single argument zombiewindow</param> if (window.chrome && zombiewindow) { if (notify === true) { // callback or alert if (typeof(callback) == 'function') { callback(zombiewindow); } else if (zombiewindow.opener) { zombiewindow.opener.alert("your popup blocker has hidden popup window instead of blocking it.\n\nplease use icon in address bar open hidden window."); } } else { // try kill zombie if (zombiewindow.opener && zombiewindow.opener.console) zombiewindow.opener.console.log('closing zombie window'); // after close, blocker icon in address bar, favicon/title not in dialog zombiewindow.close(); // optional callback if (typeof(callback) == 'function') callback(zombiewindow); } } }
so can like...
var popup = window.open(...); if (typeof(popup) == 'undefined') { // handle } else if (popup && popup.closed) { // handle } else if (ispopupzombie(popup, 100)) { console.log('popup zombie!'); handlepopupzombie(popup, true); } else { console.log('no zombies, regular ordinary popup code time!'); }
you may try check innerwidth, innerheight, outerwidth and/or outerheight. when blocked chrome seens let them @ 0. like:
window.addeventlistener('load', function(){ var w = window.open(''); settimeout(function(){ if ((w.outerwidth === 0) && (w.outerheight === 0)){ alert('blocked!'); } w = null; }, 25); }, false);
a delay of 0 not work since chrome new windows created (0,0) size, after time give proper size it.
Comments
Post a Comment