如果我启动一个带有Flash游戏的窗口,而Chrome的弹出窗口阻止程序将其抑制,则用户会听到游戏中的音乐,但看不到任何声音.这是因为Chrome浏览器不会阻止窗口;它只是将其隐藏.
Chrome会加载页面以获取收藏夹图标和页面标题,因此他们可以在弹出窗口阻止程序对话框(单击地址栏中的图标时看到该对话框)中显示它.但是,然后他们不关闭窗口.插件运行后,脚本可以回调打开器-就像常规窗口一样,但是不可见. (好的,恶意软件开发者,请不要流口水.)
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对象中有一些东西指示窗口处于不可见状态,所以我可以关闭它或移除闪光灯?
__
根据普鲁士的回答,这就是我最终得到的…
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!');
}
解决方法:
您可以尝试检查innerWidth,innerHeight,outerWidth和/或externalHeight.阻止镀铬时,将其设为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)大小创建的,只有在一段时间后才能为其设置适当的大小.