Popup Blocked Warning from Flash

I’ve noticed recently that some popup blockers will see even the target=”_blank” links as a popup. So that got me thinking about a good way to open a popup from Flash and detect if it was actually opened.

Rather than participate in the battle against popup blockers I come from the stance that popup blockers are a good thing and we shouldn’t try to find ways around them. Therefore, I think the best option is something the just warns the user if a link has been blocked. This is actually very simple with ExternalInterface.

Simply add the following JavaScript function to your page:

[as]function openWindow(url, name, width, height, x, y) {
    var params = “height=” + height + “,width=” + width + “,toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,top=” + x + “,left=” + y;
    var popup = window.open(url, name, params);
    return popup != null && typeof(popup) != “undefined”;
}[/as]Then call it from flash like this:

[as]var isOpened:Boolean = ExternalInterface.call(“openWindow”, “http://www.google.com“, “google”, 500, 500, 100, 100);
if(!isOpened) {
    trace(“This link was blocked”);

Leave a Reply

Your email address will not be published. Required fields are marked *