弹出拦截器API-如何检查用户是否已启用它 [英] Pop up blocker API- how to check if user has it enabled

查看:85
本文介绍了弹出拦截器API-如何检查用户是否已启用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道用户何时单击触发window.open的按钮,是否存在稳定的API/方式,以便事先了解用户是否主动具有弹出窗口阻止程序?

I need to know when the user clicks on the button that triggers window.open if there is stable API/way to know beforehand if the user actively has a pop-up blocker?

在某些情况下,用户不知道/没有注意他们有弹出窗口阻止程序(阻止了新窗口).我想通过单击一些对话框来通知他们,或者通过单击允许来授权一个新窗口.

In some cases the user doesn't know/pay attention that they have pop-up blocker (that block the new window). I would like to inform them by some dialog/or something to authorize a new window by clicking on allow.

推荐答案

Window.open(...)返回到新窗口的句柄(如果存在).如果它没有新窗口的句柄,则很好地表明该窗口已被阻止.

Window.open(...) returns a handle to the new window if it exists. If it doesn't have a handle to the new window, that's a pretty good indication the window was blocked.

https://developer.mozilla.org/en-US/docs/Web /API/Window/open

来自: https://davidwalsh.name/popup-block-javascript

var windowName = 'userConsole'; 
var popUp = window.open('/popup-page.php', windowName, 'width=1000, height=700, left=24, top=24, scrollbars, resizable');
if (popUp == null || typeof(popUp)=='undefined') {  
    alert('Please disable your pop-up blocker and click the "Open" link again.'); 
} 
else {  
    popUp.focus();
}

这篇关于弹出拦截器API-如何检查用户是否已启用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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