用户登录前的弹窗检测

2022-01-20 00:00:00 popup browser javascript

有没有一种好方法可以确定一个人是否启用了弹出窗口阻止程序?我需要维护一个 Web 应用程序,不幸的是它有大量的弹出窗口,我需要检查用户是否启用了弹出窗口阻止程序.

Is there a good way to determine if a person has a popup blocker enabled? I need to maintain a web application that unfortunately has tons of popups throughout it and I need to check if the user has popup blockers enabled.

我发现这样做的唯一方法是从 javascript 打开一个窗口,检查它是否打开以确定是否启用了阻止程序,然后立即将其关闭.

The only way I've found to do this is to open a window from javascript, check to see if it's open to determine if a blocker is enabled and then close it right away.

这有点烦人,因为没有启用它的用户会在窗口立即打开和关闭时看到屏幕上的小闪烁.

This is slightly annoying since users who do not have it enabled see a small flash on the screen as the window opens and closes right away.

有没有其他不显眼的方法来实现这一点?

Are there any other non-obtrusive methods for accomplishing this?

推荐答案

阅读使用 Javascript 检测弹出窗口拦截器:

基本上你检查 'window.open' 方法是否返回一个新打开窗口的句柄.

Basically you check if the 'window.open' method returns a handle to a newly-opened window.

看起来像这样:

var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
if(mine)
    var popUpsBlocked = false
else
    var popUpsBlocked = true
mine.close()

相关文章