在不打开弹出窗口的情况下检测阻止的弹出窗口 [英] Detect Blocked popups without opening a popup

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

问题描述

这个问题多次出现在如何检查弹出窗口是否在我的浏览器上被阻止中,我找到的所有解决方案都提出了一个解决方案,其中打开了一个新的弹出窗口进行测试。

This question has been raised many times on "How to check if the popup is blocked on my browser or not" and all the solutions that i found have proposed a solution where a new popup window is opened for testing.


参考文献:

References:


  1. 检测Chrome中阻止的弹出窗口

怎么能我检测到浏览器是否阻止弹出窗口?


等等

我想知道是否有可能知道阻塞的弹出窗口,而不是实际打开一个。

I would like to know if there is any possibility of knowing a blocked popup, without actually opening one.

因为很多原因导致测试弹出可能需要一段时间才能结束,这在您的应用程序的开始页面看起来很难看。

Because due to many reasons the test pop up may take time to close, which looks ugly on start-page of your application.

例如,如果我们可以使用任何东西来自来自客户端的请求标头,知道弹出首选项等,就像我们可以获得语言首选项一样。

For example if we could use anything from the request header from the client, to know the popup preferences etc like we can get for the language preferences.

这将是一个巨大的帮助。谢谢

It'll be a huge help. Thanks

推荐答案

据我所知,弹出窗口阻止程序的工作方式是覆盖 window.open 函数,在大多数情况下返回 null 。所以一种方法是检测 window.open 是否还是nativ函数。

As far as I know, popup blockers works by overwrite a window.open function and in most cases return a null. So one way is to detect if window.open is still nativ function.

你可以用<$来测试c $ c> toString 方法,返回 [native code] 作为该函数的主体。 toString 在旧的IE中不起作用,所以不要使用''+ 转换功能。

You can test that with toString method, which return [native code] as a body of that function. toString not work in old IE, so instead of that use ''+ to convert function.

var havePopupBlockers =(''+ window.open).indexOf('[native code]')=== -1;

这不是银弹,但可以发现潜在风险。我在Chrome,FF,IE8和IE9上使用一些不同的弹出窗口拦截器进行测试。

This is not silver bullet, but can detect potential risk. I test this on Chrome, FF, IE8 and IE9 with some various popup blockers and works.

这篇关于在不打开弹出窗口的情况下检测阻止的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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