如何检测 Chrome 中是否阻止了另一个域的弹出窗口?
您可以使用以下问题的解决方案来检测 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将受到所有常见的同源策略的约束,我建议直接阅读它们: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?