May 20 2008

Allowing Popups to work

Published by at 11:02 am under AS 3.0,Flash

In AS 2.0 or earlier when you use getURL to open up a new browser window, usually it wouldn’t get blocked by popups if the getURL call was made onRelease event instead of onPress. But with navigateToURL introduced in AS 3.0 its a different story altogether. 

navigateToURL works fine with Safari but doesn’t work in Firefox (I am a mac user so i personally test in these two browsers). Anyway to make sure that popups open we have to use some javascript and call it from our Flash.

Adobe recommends we use ExternalInterface since the 9.0.124 update. So here is my Flash code,

var boolean:String = ExternalInterface.call("openWindow", url);

if (boolean == "false"){
    navigateToURL(new URLRequest(url),"_blank");

}

and my Javascript would look something like this,

function openWindow(pageUrl) {
    var winName = Math.round(9999*Math.random()) + new Date().getTime();
    var winNew = window.open(pageUrl,winName,"toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=700,left=200,top=100");

        if(!winNew) {
            return "false";
        } else {
            return "true";
        }
    }

So with this method we first try to open a window using Javascript, Firefox is happy with that and hence it returns true and flash doesn’t make a call to navigateToUrl. Safari blocks the javascript popup and hence true is returned to Flash and using navigateToUrl you can open up a new browser window.

It seems to work with IE as well otherwise i would have got a bug reported from the QA team. :)

7 responses so far

7 Responses to “Allowing Popups to work”

  1. Kevinon 05 Dec 2008 at 9:06 am

    I keep getting a “null” error when I try this.

  2. Nayanon 05 Dec 2008 at 9:31 am

    what do you exactly mean by that? could you clarify further…..

  3. Kevinon 05 Dec 2008 at 9:47 am

    Sure. It works great in both Firefox and Safari. But in IE nothing happens and I get a javascript error that says “null is null or not an object.”

  4. Kevinon 05 Dec 2008 at 10:14 am

    Also, so this function is essentially using “_blank” if it can’t open via javascript. Is there any way to set the window size?

  5. Nayanon 05 Dec 2008 at 5:27 pm

    i think in IE there might be some problem with establishing the externalinterface call or something is wrong with window.open in IE, i haven’t had any problems, is there a specific version of IE in which the problem happens.

    navigatetoURL as far as i know doesn’t have parameters to change the window size.

  6. […] it might be because of popup blocker. To avoid popups from Flash i have written another post, Avoiding Popup Blockers     Download the fla file here. […]

  7. radiosite.caon 13 Dec 2015 at 11:44 am

    Yes! Finally something about radio broadcasting.

Trackback URI | Comments RSS

Leave a Reply