简体   繁体   中英

How do you detect if a popup to another domain was blocked in Chrome?

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);
}

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM