我知道javascript技术可以检测弹出窗口是否在其他浏览器中被阻止(如本问题的答案中所述).这是基本测试:
var newWin = window.open(url);
if(!newWin || newWin.closed || typeof newWin.closed=='undefined')
{
//POPUP BLOCKED
}
Run Code Online (Sandbox Code Playgroud)
但这在Chrome中无效.弹出窗口被阻止时,永远不会到达"POPUP BLOCKED"部分.
当然,测试工作到一定程度,因为Chrome实际上并没有阻止弹出窗口,而是在右下角的一个微小的窗口中打开它,列出"阻塞"弹出窗口.
我想做的是能够判断弹出窗口是否被Chrome的弹出窗口阻止程序阻止.我试图避免浏览器嗅探,以支持功能检测.有没有办法在没有浏览器嗅探的情况下做到这一点?
编辑:现在我已经尝试利用的newWin.outerHeight,newWin.left以及其他类似性质的做到这一点.当弹出窗口被阻止时,Google Chrome会将所有位置和高度值返回为0.
不幸的是,即使弹出窗口实际打开了一段未知的时间,它也会返回相同的值.经过一段神奇的时期(在测试中几秒钟),位置和大小信息将作为正确的值返回.换句话说,我仍然没有更接近解决这个问题.任何帮助,将不胜感激.
我在堆栈溢出中搜索了很多问题,可能在这里 重复检测Popup
但not helped for me同时,在测试中铬(测试v26.0.1410.64)
下面的方法Worked in IE and Firefox,但not in Chrome
var popup = window.open(winPath,winName,winFeature,true);
if (!popup || popup.closed || typeof popup.closed=='undefined'){
//Worked For IE and Firefox
alert("Popup Blocker is enabled! Please add this site to your exception list.");
window.location.href = 'warning.html';
} else {
//Popup Allowed
window.open('','_self');
window.close();
}
Run Code Online (Sandbox Code Playgroud)
任何适用于Chrome的更好的解决方案呢?