如果我启动一个带有Flash游戏的窗口,并且Chrome的弹出窗口拦截器会阻止它,则用户会听到游戏中的音乐,但什么也看不见。这是因为Chrome不会阻挡窗口;它只是隐藏它。
Chrome会加载页面以获取favicon和页面标题,因此他们可以在弹出窗口阻止程序对话框中显示它(您在单击地址栏中的图标时会看到该对话框)。但他们并没有关闭窗户。插件运行,脚本可以回调给开启者 - 它就像一个常规窗口,但看不见。 (好的,恶意软件开发者,请停止流口水。)
Chrome可以解析< head>的内容标记以检索< title>和favicon< link />标签没有实际加载页面。他们可以在检索到图标/标题后关闭隐藏的窗口。他们只能显示URL而不是图标/标题。相反,自2008年以来,这个虫子继续恶化......
http://code.google.com/p/chromium/issues/detail?id=3477
http://code.google.com/p/chromium/issues/detail?id=38458
无论如何,问题是:我可以检测到这种情况何时发生?也许window.chrome JavaScript对象中有一些东西表明窗口处于这种不可见状态,所以我可以关闭它或者删除闪光灯?
__
根据Prusse的回答,这就是我最终的结果......
function isPopupZombie(popWindow, delay) {
/// <summary>Attempts to detect zombie window "blocked" (hidden) by 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 to close the zombie or alert about Chrome FAIL</summary>
/// <param name="zombieWindow">Popup window object known to be a hidden but unblocked popup</param>
/// <param name="notify">true to notify user of hidden window, false to close zombieWindow</param>
/// <param name="callback">optional function to call, with single argument for 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 a popup window instead of blocking it.\n\nPlease use the icon in the address bar to open the hidden window.");
}
} else {
// try to kill the zombie
if (zombieWindow.opener && zombieWindow.opener.console) zombieWindow.opener.console.log('Closing zombie window');
// after close, blocker icon is in address bar, but favicon/title are not in dialog
zombieWindow.close();
// optional callback
if (typeof(callback) == 'function') callback(zombieWindow);
}
}
}
所以我可以做点像......
var popup = window.open(...);
if (typeof(popup) == 'undefined') {
// handle it
} else if (popup && popup.closed) {
// handle it
} else if (isPopupZombie(popup, 100)) {
console.log('popup zombie!');
handlePopupZombie(popup, true);
} else {
console.log('no zombies, this is regular ordinary popup code time!');
}
答案 0 :(得分:3)
您可以尝试检查innerWidth,innerHeight,outerWidth和/或outerHeight。当阻止铬色时让它们处于0.喜欢:
window.addEventListener('load', function(){
var w = window.open('');
setTimeout(function(){
if ((w.outerWidth === 0) && (w.outerHeight === 0)){
alert('blocked!');
}
w = null;
}, 25);
}, false);
延迟为0将不起作用,因为对于chrome,所有新窗口都是使用(0,0)大小创建的,只有在一段时间后它才会给它一些合适的大小。