如何检测 Chrome 中是否阻止了另一个域的弹出窗口?

发布于 2024-11-07 08:11:10 字数 451 浏览 0 评论 0原文

您可以使用以下问题的解决方案来检测 Chrome 中的弹出窗口是否已被阻止:检测阻止的弹出窗口Chrome

然而,解决方案似乎是检测到同一域上的页面的弹出窗口。我想知道是否有一种方法可以检测另一个域上的页面弹出窗口是否被阻止?

var newWindow = window.open('http://www.google.com/'); // this domain is something.com
if (newWindow) {
    setTimeout(function() {
        // Is there a way to detect if newWindow was blocked?
    }, 500);
}

You can detect whether a popup has been blocked in Chrome with the solutions to this question: Detect blocked popup in Chrome

However, the solutions seem to be detect is a popup for a page that is on the same domain. I was wondering if there was a way to detect if the popup for page on another domain was blocked?

var newWindow = window.open('http://www.google.com/'); // this domain is something.com
if (newWindow) {
    setTimeout(function() {
        // Is there a way to detect if newWindow was blocked?
    }, 500);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清君侧 2024-11-14 08:11:10

您将受到所有常见的同源策略的约束,我建议直接阅读它们:http ://en.wikipedia.org/wiki/Same_origin_policy。简而言之,您正在尝试进行跨域通信,这是浏览器的安全模型所禁止的。为了解决这个问题,有服务器端代理、JSONP、Flash、document.domain(但前提是它是两个不同的子域)以及一系列的黑客,这些黑客的成功程度取决于您的支持要求和您的具体需求。试图做。

您能告诉我们更多有关您的浏览器支持要求的信息吗?您可以使用 XHR 2 级吗?您尝试在弹出窗口中加载的页面是什么?

You'll be bound by all the usual same origin policies, and I'd recommend reading up on them directly: http://en.wikipedia.org/wiki/Same_origin_policy . In short, you're trying to do cross-domain communication, which is prohibited by the browser's security model. To get around it, there are server-side proxies, JSONP, Flash, document.domain (but only if it's two different subdomains), and a bevy of hacks that work with varying success depending on your support requirements and what exactly you're trying to do.

Can you tell us more about what your browser support requirements are? Can you use XHR Level 2? What's the page you're trying to load in the popup?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文