如何检测是否在chrome中阻止了弹出窗口 [英] How do I detect whether popups are blocked in chrome

查看:129
本文介绍了如何检测是否在chrome中阻止了弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载facebook auth页面,以便用户将他们的fb帐户与我的网站连接。问题是它是一个不同的领域。代码如下

I'm trying to to load facebook auth page for users to connect their fb accounts with my site. The problem is it's a different domain. Code is as below

var left = (screen.width/2)-(550/2);
    var top = (screen.height/2)-(250/2);
    fbPopUp = window.open(authorizeURL,'fbWindow','menubar=0,status=0,titlebar=0,toolbar=0,resizable=1,width=400,height=275, top='+top+' , left='+left);

如何确定此窗口是否实际打开?
我尝试了检测Chrome中阻止的弹出窗口的解决方案

How do I find out whether this window actually opened or not? I tried solution of Detect blocked popup in Chrome

推荐答案

基本上Chrome中存在一个错误。虽然它隐藏了弹出窗口,但它仍然会执行,你仍然可以恢复窗口对象 - 所以定期检查不起作用。

Basically there's a bug in Chrome. Although it hides the popup, it still executes and you still get the window object back - so regular checks don't work.

这是适用于我的解决方案:

Here's the solution that worked for me:

var popup = window.open(url);

if (popup) {
  popup.onload = function () {
    console.log(popup.innerHeight > 0 ? 'open' : 'blocked');
  }
} else {
  console.log('blocked');
}

这里的工作示例:http://jsbin.com/uticev/3/

这篇关于如何检测是否在chrome中阻止了弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆