By default, browsers with a built-in popup blocker will usually block Flash navigateToURL requests that open in a “_blank” window. For example: navigateToURL(“http://www.google.com”, “_blank”); will generally get blocked. Even if you have a mouse click event to send off the navigateToURL call, it will be blocked.

The good news is that you can get around this behaviour by calling out to JavaScript to handle the request for you. Go ahead and download URLNavigator.as and save it as ~/com/zorked/URLNavigator.as, where ~ is the folder that your FLA or Flex project resides within. In your ActionScript code, import com.zorked.URLNavigator, then call out to method with URLNavigator.ChangePage(“http://www.example.com”, “_blank”); in the mouse event that you’re capturing.

Now, I’ve tested this with a variety of systems, and it works on a lot of them but it’s not foolproof. So far, it works in IE 6, 7, & 8 (beta), Firefox 2 & 3, Opera 9.x, Safari 3, and runs on XP, Vista, and OSX. It may work on additional systems, but my testing is limited. You may also have problems if you embed your SWF in a strange way. It seems to work with most JavaScript embed libraries, but different parameters on the <object> and <embed> could conceivably cause problems.

However, the caveat is this: you CANNOT call this code except within a click mouse event that you’re listening for. Popup blockers will rightfully block an automatic popup, and there is no way around it. If you ask me how to do an auto-popup, I’ll find your house while you’re sleeping; this method is for white-hat developers looking to open a new browser window for good reason.

Additionally, I made an update to the link that was originally saved: Wordpress likes to save files as lowercase names, which Flash had problems with, since the file didn’t match the name of the class. You should be able to download and work with it without having to rename it.

I’m open to suggestions and improvements, and if anyone has access to additional browsers or operating systems that it’s worked for them on, please let me know.

Download: URLNavigator.as

115 Responses to “Popups Blocked in AS3 with navigateToURL()”
  1. Thanks
    worked perfectly.

  2. Thanks too :)

  3. Forgive this newby, but where do I place the .as file?

    And finding this was a GodSend!!! Thanks. WCW

  4. Hi Willow,

    You can save the .as file into /com/zorked/URLNavigator.as, relative to your .fla. So, if your .fla is at /Documents/MyApp.fla, you would save it as /Documents/com/zorked/URLNavigator.as.

    In your .fla or other .as files, you’ll import com.zorked.URLNavigator.

  5. Thanks for the start. Now what do you mean by “import com.zorked.URLNavigator?

    Here is my simple code. There is an image in a frame that I’ve made into a button, and named an instance of that button. I want the button to link to an outsie URL…..so simple.

    Code:
    dooWop_btn.addEventListener(MouseEvent.CLICK, goToTvPledge);

    function goToTvPledge(e:Event):void
    {
    var tvPledgeRequest:URLRequest = new URLRequest(“https://pledge.wusf.usf.edu/wusftvdefault.asp?p=TVWEB”);
    navigateToURL(tvPledgeRequest);
    }

    When I use it, I get the Pop-blocked error….I just need to get this link to work.

    I’ve downloaded your .as file and placed it where you suggest. Now what? How do I modify my code so that it will activate or whatever it’s supposed to do in relationship to that.as file? Or does the .as file replace it? Am I supposed to modify something on that file or in my code?

    And why is this so complicated? All I want to do is make a few frames in my flash document link to an outside Website.

    Sorry to be dumb about this, and whatever you can do to assist me, I will appreciate. WCW

  6. The first line in your frame will need to be:

    import com.zorked.URLNavigator;

    This tells Flash to compile that file into the SWF so that the rest of your code in the .fla can use it.

    Then, replace the code inside of your goToTvPledge() function with:

    URLNavigator.ChangePage(“https://pledge.wusf.usf.edu/wusftvdefault.asp?p=TVWEB”, “_blank”);

    The reasons that this process is complicated are
    1. Programming Is Hard
    2. Flash is primarily an animation platform that’s had a programming framework crowbared in, so wrapping your head around how Flash expects things takes some time.

    I suggest researching Document classes. That helps clean up your code by keeping it separated from your UI, the .fla.

  7. Willow Wright says:

    Wow! Thanks so much for your quick and generous reply. I’ll give it a try. And a hearty LOL about programming is HARD! :) I will keep at it, for sure! and I will definately continue to study.

    Gratefully, WCW

  8. I am getting these errors in Flash when I place the code you suggest.

    1093: Syntax error.
    1084: Syntax error: expecting rightparen before colon.

    This is what I wrote: Have I placed the code in the wrong place?

    adjusted Code:
    import com.zorked.URLNavigator;

    dooWop_btn.addEventListener(MouseEvent.CLICK, goToTvPledge);

    function goToTvPledge(e:Event):void
    {
    URLNavigator.ChangePage(“https://pledge.wusf.usf.edu/wusftvdefault.asp?p=TVWEB”, “_blank”);
    }

    Thanks, WCW

  9. The code is correct, but Wordpress is formatting the quotes, so Flash doesn’t recognize them. Just replace the fancy quotes with normal ones. Retyping them in your text editor should be fine.

  10. Thank you so much for your patience and assistance. Everything is working fine, now.

    It was working in the standalone HTML file that Flash produces, when you publish the .fla, but not when I embedded it in the actual page it needed to appear in. But I found that I was still using old code from AS2 days to embed the file, with a hack to resolve some IE issues.

    Once I replaced the Embed code, all is working fine, now.

    I am most grateful. Thanks again. WCW

  11. Been working with this all day. This and similar code do not work on Vista — both IE and Firefox block the popup…

  12. Hi Greg,

    I’ve tested this code on a variety of machines, including Vista. Unless there’s been a very recent update to IE popup blocking, it should work.

    My guess is that for some reason, ExternalInterface.available is returning null for you. It may do that if you’re just opening an HTML file on your hard disk rather than over localhost, or if Flash isn’t recognizing the ExternalInterface because of the way you’re embedding the SWF onto the page.

    If you want to email your files to me, I’ll take a look. jordan@zorked.com

  13. it’s not working..

  14. I need more info than that Vincent. Can you tell me what errors you’re getting and how you’re embedding your SWF into the HTML?

  15. nop . it is not working !!

  16. It works for me with the latest FireFox (2.0.016) but not in IE7 any suggestions?

  17. Link 404 not found

  18. This works well, including for Safari on Windows and Mac. Appreciate it!

  19. Great, Thanks for the script. I’m having a small issue, maybe you can help me out. I’ve looked everywhere for the fix but it’s been kicking my butt for a couple of days. I’m pretty new to Flash and Actionscript.

    I’ve placed the folder in the place (screenshot)

    http://www.broketravelers.com/screenshot.jpg

    and I import it.

    import com.zorked.*;
    -or-
    import com.zorked.navigatetourl;

    but when i call the function:

    private function runOnce(event:TimerEvent):void {
    URLNavigator.ChangePage(“http://www.adobe.com”);
    }

    I get the code:

    Error #1065: Variable URLNavigator is not defined.

    Head scratcher for me. Any help is Appreciated. I dont think I’m importing it correctly. But other .as files I am importing are importing correctly. Thanks a bunch!

  20. I keep getting a variable URLNavigator is not defined. Everything is imported correctly. any ideas?

  21. Samantha, you’ll need to put the class in a /com/zorked/ folder relative to your FLA. Then, you can import com.zorked.URLNavigator.

    Like this
    MyFolder/MyFile.fla
    MyFolder/com/zorked/URLNavigator.as

  22. Do i need to change the paramaters inside of URLNavigator or is it fine how it is?

  23. You shouldn’t have to edit URLNavigator. You can pass either a URLRequest object or a string, along with the window you want it to open in (usually “_blank” for a new window).

    I suppose I ought to edit this post with comments and usage notes, but you can just do:
    URLNavigator.ChangePage(“http://www.google.com”, “_blank”);

  24. Great! thanks! works like charm. I saved the .as file as urlnavigator.as instead of URLNavigator.as

    Silly me! keep up the good work! ;)

  25. but window.open also gets blocked by popupblockers!!!

  26. Hi, this solution not longer works in Firefox version 3 if the pop-up blocker is on. It seems that Firefox version 3 is more stringent with pop-ups.

  27. Mike, I’ve just now tested it and it worked. This method will only work if you call URLNavigator.ChangePage within a MouseEvent.CLICK listener; is that possibly the reason it’s not working for you?

  28. jordan,

    wow, this is a really great way to get pop ups!!! I have been working on this for a few days now and your way works. was wondering if there is any way to control the window even more, such as size, location where the window pops up? if you know how and any more attributes please do tell … thank you again … themadcow

  29. Cow, you can modify URLNavigator to change the ExternalInterface.call line.

    In JavaScript, window.open looks like this: window.open(url, windowName, features);

    Take a look at Mozilla’s docs for what you can put for “features”: http://developer.mozilla.org/en/DOM/window.open

    So in Flash, the ExternalInterface.call might look like this:
    ExternalInterface.call(“window.open”, req.url, window, “width=400,height=500,top=50,left=200″);

    I’ll probably modify URLNavigator so that you can pass that stuff in–good idea.

  30. jordan,

    i tried to replace this in the URLNavigator and I found no result? i am actually trying to make a navigation with three buttons that all call javascript pop ups? I noticed that if you try to copy and paste the code for the next button in the navigation and you receive a duplicate function issues as well. is there anyway you can send me a tid-bit of code regarding this first issue and now the following issue? thank you.

    kind regards … cow

  31. Cow, I’m pretty sure you’re not using the URLNavigator correctly. Are you saving and importing it like I wrote about in the 2nd paragraph in my post?

    I can’t really tell what you’re trying to do, but send me an email with the files you’re working with and I’ll see if I can help you.

  32. Fedora 8 ff3 without any addition plugins – not working

  33. firefox 3.03 not working with this.

  34. [...] initially thought that a popup blocker was probably causing the problem with navigateToURL() so I tried exploring changing the AllowScriptAccess parameter to “always” and use [...]

  35. Thanks so much for all of the trouble you’re going to to field individual questions.

    I keep getting the error message: “5001: The name of package ‘com.zorked’ does not reflect the location of this file. Please change the package definition’s name inside this file, or move the file.

  36. Hi Doug, you have 2 options.

    1: edit URLNavigator.as so that it says package { instead of package com.zorked {
    2: relative to your .fla, create a folder called “com”, and a folder called “zorked” inside that. Put URLNavigator.as in that folder. For more detailed info, read the 2nd paragraph in my post.

    Thanks for using it!

  37. terbooter and jared, would you please test at the following URL?

    URL Navigator Test

    If it works, then you may have a problem with the way you’re embedding your swf, though I’ve used lots of different methods with success. Let me know either way.

  38. I have a defined javascript function that I am trying to call that opens up a popup. Using this method, it doesn’t seem to know how to handle it. Is there a way to use a javascript function?

  39. Okay, I’m getting this to work locally, but when I try it up on a server, I’m getting errors from FF3:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at com.zorked::URLNavigator$/ChangePage()
    at bosch_300×600_120508_c_fla::MainTimeline/goToURL()

    Since it works locally, I’m pretty sure that it’s been embedded into the flash correctly. I’ve even tested your URL Navigator Test. And THAT works as well so there must be something I’m missing. Is there any way you can post your flash file for the URL Navigator Test? I’m going crazy.

  40. Sorry – here’s how I’m calling it:

    import com.zorked.URLNavigator;
    bttnInv.addEventListener(MouseEvent.CLICK,goToURL);

    function goToURL(e:MouseEvent):void
    {
    var url:String = root.loaderInfo.parameters.clickTag;
    URLNavigator.ChangePage(url, “_blank”);
    }

  41. I think I’m discovering the issue. If the swf and the html files aren’t in the same directory, they don’t work.

  42. Hello! i am trying to fix this pop-up problem with your advice but i can’t get it work.
    It say’s An actionscrip error occured: SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file:///D:/Publicitate/Promo Berca/site Berca/swf/1.swf cannot access file:///D:/Publicitate/Promo Berca/site Berca/sus.html.
    at flash.external::ExternalInterface$/flash.external:ExternalInterface::_initJS()
    at flash.external::ExternalInterface$/call()
    at com.zorked::URLNavigator$/ChangePage()
    at 1_fla::MainTimeline/gotoSite()

    ————————————————————————————-

    here is my as :

    stop();
    import com.zorked.URLNavigator;
    var rewind:Boolean = false;
    myBT.addEventListener(MouseEvent.ROLL_OVER,growUP);
    myBT.addEventListener(MouseEvent.ROLL_OUT,growDown);
    myBT.addEventListener(MouseEvent.CLICK,gotoSite);

    myBT.buttonMode = true;
    myBT.useHandCursor = true;

    function growUP(e:MouseEvent):void{
    play();
    rewind = false;
    }

    function growDown(e:MouseEvent):void{
    rewind = true;
    }
    function gotoSite(e:MouseEvent):void{

    URLNavigator.ChangePage(“jos.html”,”_blank”);
    }

    this.addEventListener(Event.ENTER_FRAME,revFrame);
    function revFrame(e:Event):void{
    if(rewind == true){
    prevFrame();
    }
    }

    Any help would be appreciated. Ty!

  43. Hey, first of all this code is awesome! First and only place I’ve actually found a solution to this problem!!!

    so, Thank you for that!

    Here’s my problem, heh heh.. it works on all of my nrmal links, but one of my links is a “donate” -paypal button. so the buttons code looks like this:

    function paypalClick(event:MouseEvent):void
    {
    var request:URLRequest = new URLRequest(“https://www.paypal.com/cgi-bin/webscr”);
    var paypal_lv:URLVariables = new URLVariables();

    paypal_lv.cmd = “_s-xclick”;
    paypal_lv.hosted_button_id = “123456″

    request.data = paypal_lv;
    request.method = URLRequestMethod.POST;

    navigateToURL(request, “_tab”);
    };

    now.. I cant figure out a way to add the “urlnavigator.ChangePage….” in there so that it would get it. Seems like that code, for some reason needs to first request the url and then enter the paypal_lv data.. and then After that, navigate to the url..

    I found a guide in writing that code at this place: http://www.photoshopcafe.com/cafe/viewthread.php?tid=43611
    incase it helps.

    Idk. I’ll keep trying, would love the help from somebody.. I’m thinking either it’s super easy, or it can’t be done..

    Thanks!

  44. Kevin, you should be able to just call your JavaScript function without using the URLNavigator: just use ExternalInterface.call(“NameOfMyFunction”);

  45. Draco, it looks like you’re testing this locally. It will probably work fine if you use it within a website; you’re currently hitting Flash Player sandbox errors. You may try looking up Flash Player sandbox and allowScriptAccess on Google.

  46. Lucas, URLNavigator doesn’t currently support posting, since JavaScript’s window.open command is GET-only. However, maybe you can use this: http://www.webdeveloper.com/forum/showthread.php?t=1688

  47. Thanks for the quick response!

    I quickly tried using the guide at webdeveloper, but got a bunch of errors like so..

    1120: Access of undefined property window.
    1120: Access of undefined property html.
    1120: Access of undefined property newWindow.

    as if I was missing some “.as” document.. so I’ll look into it later and maybe hit you back if I’m getting closer but still can’t get it to work completely, thanks again!

  48. Anyone else still getting pop up blocked in IE7?

  49. This is my code btw:
    import com.zorked.URLNavigator;

    link_btn.addEventListener(MouseEvent.CLICK,goToURL);

    function goToURL(e:MouseEvent):void
    {
    var url:String = root.loaderInfo.parameters.clickTag;
    URLNavigator.ChangePage(“http://www.threeleafmusic.com/posters”, “_blank”);
    }

  50. Hi Chris, it looks like your AS code is correct. How are you embedding the Flash into your page?

    Try visiting: http://labs.zorked.com/lib/URLNavigatorTest.html in IE7. It pops up a new window correctly on my PC, so it’s probably not a problem with IE7.

  51. Hi Jordan,

    You are so good for providing us your wonderful code.
    Especially your patient and helpful for others.
    Really appreciate
    Thanks

  52. [...] initially thought that a popup blocker was probably causing the problem with navigateToURL() so I tried exploring changing the AllowScriptAccess parameter to “always” and use [...]

  53. Hi I have a ‘flipbook’ at htttp://www.eti1.co.uk/eti_flipbook

    I need this to open a new window when a page is clicked on – this is currently being blocked by IE7 & Firefox

    Am using the following actionscript – have tried integreating your code as instructed – but keep getting error messages – help!? Thanks – Barry

    myBook.onClick = function(pageNumber, page_mc, isCornerClick) {
    // Don’t open new HTML page by corner click
    if (isCornerClick) {
    return;
    }
    // Get needed URL from XML file
    var URL = page_mc.params.URLToOpen;
    if (URL != undefined) {
    getURL(URL, “_blank”);
    }
    };
    // For better usability I turned off flipOnClick parameter
    // So, page won’t start flipping by mouse click
    // But we need to enable it for corners
    myBook.onStartFlip = function() {
    this.flipOnClickProp = true;
    };
    myBook.onFlipBack = function() {
    this.flipOnClickProp = false;
    };
    myBook.onPutPage = function() {
    this.flipOnClickProp = false;
    };

  54. Hi Barry, you need to save the URLNavigator according to the instructions I have in the article, and then add the import statement at the top. Then, you can replace, the getURL with URLNavigator.ChangePage(URL, “_blank”);

    Let me know if you need more help.

  55. Hi Jordan,

    your test link doesn’t work in Firefox 2.0.0.20 (http://labs.zorked.com/lib/URLNavigatorTest.html) – pop up blocked

  56. [...] via:http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/ [...]

  57. Hi all,

    This code doentworks on my PC / XP / IE 7.
    nor does ur testlink.

  58. Hello, in flash it just works fine, when I put it on line it works fine too when I go through the “http://” way, but as soon as I try by : “http://www.” it don’t work anymore, on your test link page I saw that you did a trick to avoid the www. how did you do thaht?
    Sorry for my english by the way… ;-)

  59. Thank you very much for the class, it is very helpful. But still doesn’t want to work in Firefox 3 :( .
    It works perfectly, though in IE 8, Opera 9, Safari 3.2.1 (for Windows) and Google Chrome.

  60. Hi,
    I need to call a function which resides in a javascript function (this javascript function opens a new window, which is currently getting blocked). How can I use the above solution?

    Thanks

  61. Having the same problem as – only in Safari 4 (beta) though…

  62. Hi Jordan.
    Thanks so much for this code. It is working for me on both IE and FF. Have you done anything on parameters to control the size of the new window that opens? I tried req.url, window, “width=400,height=500,top=50,left=200″);
    per your suggestion and I get an error that it is expecting only 2 parameters.
    Any help you can give would be much appreciated.
    Larry

  63. Thanks, Firefox is retarded with popups and flash. This has become a standard library component for my flash development. Thanks!

  64. Thanks a lot for posting your code Jordan. I am new to flash AS3 and this really helped me out a lot creating a flash menu for a relative who had an HTML website with frames. ( I don’t know if it’s efficient, but it’s all I know :P ). Anyway after countless hours of searching I have found your working code! You saved my day!

  65. Krishna, I don’t think you can open a new window without directly calling window.open because the JavaScript mouse event scope gets lost and it will get blocked.

    foley, I haven’t tested in Safari 4, but I can’t do much about it since it’s a beta.

    Larry, the signature for the window.open JavaScript function is window.open(url, name, parameters). Parameters is a comma delimited list like you have, but in URLNavigator.ChangePage, it only uses url and name. You’ll need to modify the JavaScript call and the signature of URLNavigator.ChangePage to pass parameters through.

    For those that have posted that it doesn’t work, please let me know if it works whenever you try the test link. If not, I need to know your system settings to troubleshoot. Send me an email and we can try to work it out.

  66. Hi,

    Thanks for the code! So far it works, but I am trying to make a fixed size window pop-up. I tried the advice you gave earlier in the thread at reply 31. But there were no changes. The page still loaded as normal, not to the fixed window size.

    Here’s what my code looks like in the saved URLNavigator.as file

    ExternalInterface.call(“window.open”, req.url, window, “width=400,height=500,top=50,left=200″);

    Any thoughts on why this isn’t working?

  67. Hey,

    It doesn’t seem to work when it is imported into the document class…
    Any ideas?

    Thanks.

  68. Sorry…

    I’ve realized that the problem is caused if it is used in conjunction with SWFObject…
    Although I’m not sure why.

  69. I was wondering if anyone has had any experience using this popup blocker/work-around in a Content Management System, where there are no directories?

    All of my data files use this path /files/ so, would my import code be files.URLNavigator.as ?

    Thank you in advance.

  70. Also, just for you fellow newbies, I wasted a lot of time trying to get this work-around to work, and then realized I had a file supplied by a fellow co-worker that was an AS2 Flash file. This only works with AS3. So, I copied all the frames/layers and pasted them into a new AS3 file. Then, I realized that the AS code was on his button, and not on the first frame of the timeline. When I placed this code into the first frame of my timeline, it worked.

    import com.zorked.URLNavigator;

    btnBuyNow.addEventListener(MouseEvent.CLICK, goToBuyNow);
    function goToBuyNow(e:Event):void
    {
    URLNavigator.ChangePage(“https://webhost.corecashless.com/indianabeach/ticketsales”,”_blank”);
    }

    I hope this is helpful to someone.

  71. Help Please.

    I have this popup blocker working on a normal web server. However, I need it to work in a content management system, where pages are accessed using the domainname.com/pages/ and files are accessed using the path either /files/ or domainname.com/files/, so that leads me to ask, how do I apply this path inside Flash’s action panel. I’ve tried numerous paths and even tried to edit the URLNavigator.as file, but keep getting an error that says, “Syntax error: extra characters found after end of program.” with the Source: import “URLNavigator”; Of course, the source changes with each new path I try to use to load the AS file from within the CMS.

    Any help is appreciated.
    elizabeth ;-)

  72. This seems to work great at prevent the pop ups from being blocked but i tried setting them to open at a specific size and i am having a bit of an issue.

    It seems to open pop-ups in the correct size in FF and IE but not in Safari. Any idea why it wouldnt work correctly in Safari? Is there something i can add to the .as file that might make it work in Safari?

    Thanks!

  73. Thanks a lot for the script it WORKS !!! I had problems at the beginning like some of the people but it was my fault, because I was implementing things in wrong way. Thanks a lot again you saved ma a lot of time.

  74. Eriq and Alex, you might both be having the same problem. URLNavigator only calls the ExternalInterface in the required versions of FF and IE that tend to block popups. If you want it to work the same on all browsers, you can mod it to always call the ExternalInterface instead of the if/else block that’s in there currently.

    However, if that’s the case, you really don’t need this class; you can just straight up call the ExternalInterface code.

  75. Elizabeth, you would import the URLNavigator class from wherever you’ve saved it out. By default, it’s supposed to go in ./com/zorked/URLNavigator.as, relative to your .fla or Flex project. However, you can save it out anywhere you want to, just make sure to change the package name in the class to match the path.

    This article may help you: http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000796.html

    Regarding the CMS, that really shouldn’t matter. Once you have your swf compiled, you don’t need to have the URLNavigator class out on your server anywhere.

  76. Thanks for the code! It works perfectly on my IE7. However, it doesn’t work on IE6… is there any code that I need to change so that it would work for IE6 as well? Thousand thanks for your help!!!!!!

  77. I figured out the solution now. I found that after I changed the “7″ in URLNavigator.as to “6″, then it will work for IE6 also…

  78. Hi, it works great, i did it like that in your class : ExternalInterface.call(“window.open”, req.url, window, “width=400,height=500,top=50,left=200″); and it’s ok for FF on mac,
    is there a way to pass the width and height for the “navigateToURL” ?
    I tried to catch it but no way, so the pop up have just the good size on FF no safari..

  79. Yes, that is correct Jenny. Generally IE6 doesn’t have as strict (or intelligent) of popup blocking as IE7+ do, so the workaround piece of the URLNavigator only runs for IE7+ and Firefox.

    Renaud, there is no way to call the width and the height on navigateToURL, but you can run javascript that resizes the window from the page that you are calling.

  80. Works great! Thanks for the awesome work!

  81. If you copy and paste the script from this page, as is, change the quotes to “normal” quotes.

  82. Its not working with IE8 but working fine on FF, whts the issue, can we run this on IE also?

  83. hi ,
    m trying to use your .as file …. but when i uploaded my .swf file into the server and trying to access that file i m getting an error ..

    SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller http://www.xyz.com/testingPlayer.swf cannot access file:///D:/work/flash%20file/widget_file/currently%20uploaded/widget.html.
    at flash.external::ExternalInterface$/_initJS()
    at flash.external::ExternalInterface$/call()
    at com.zorked::URLNavigator$/ChangePage()

    can you suggest me , so that i can solve this problem…

  84. Does it pay to try to share code? I’m glad you did, but wow – that’s a lot of BS Q’s up there.

  85. @niks, you can’t access local file system pages from a website. That’s a terrible security risk. Upload that widget.html page to your server and reference it with a relative URL.

    @Sachin, it should work on IE. Please try the test URL and let me know if that doesn’t work for you

    @Josh, unfortunately it doesn’t pay to share code. Normally I don’t, as you can tell by the limited amount of posts. However, this is the most popular code on my site by far, and there are a lot of people that haven’t integrated 3rd-party code before, or just don’t know Flash very well. That’s the majority of the questions.

  86. A few things I found out while tinkering w/ this:

    1.) your swf file and html file do not have to be in the same directory, as #43 mentioned. a working directory structure is something like the following:

    ./flash/flashfile.swf
    ./com/zorked/URLNavigator.as
    ./your-page-containing-flashfile.html

    just make sure the “com” folder is in the same directory as your html file.

    2.) the “wmode” param in my embed code was giving me issues with IE8, so removed it and everything worked fine. Just thought I’d mention in case anybody runs across the same problem.

  87. It works perfectly.
    Thanks man !

  88. THANK YOU!!! This was very helpful.

  89. Thanks for your information, it’s really helpful !

  90. Thanks a lot dude ! says:

    Thanks Thanks Thanks Thanks Thanks !!

  91. divisionby0 says:

    Didn’t can use it with swfObject.js
    Using AC_RunActiveContent.js made me happyyyyy :)
    Thanks a lot for this usefull class.

  92. I am a student about to graduate and needed this for my portfolio show on Wednesday – and it works perfectly! Thanks SO much!

  93. Another happy user, thanks!

  94. Thank you very much, works perfectly.

  95. I’m surprised ppl are saying this still works… I’ve read through the posts (Jordan is a very patient man :) , I am a very experienced programmer and have to tested this carefully. I set up an extremely simple test case, not using swfObject, just one button on the stage in one script with the subroutine included, and the pop-up is blocked by IE8.

    Here is the single class that I’m compiling the swf from:

    package m2g.tests {
    import flash.display.Graphics;
    import flash.display.SimpleButton;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.external.ExternalInterface;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    /**
    *
    * @mxmlc -debug
    */
    public class TestPopup extends Sprite {

    private var _test:int;

    public function TestPopup() {
    var btn:Sprite = new Sprite();
    var gr:Graphics = btn.graphics;
    gr.beginFill(0×00FF00);
    gr.drawRect(0, 0, 40, 40);
    gr.endFill();
    btn.addEventListener(MouseEvent.CLICK, _testClick);
    btn.buttonMode = true;
    btn.useHandCursor = true;
    addChild(btn);

    }

    private function _testClick(e:MouseEvent):void {
    ChangePage(“http://www.tunegenie.com/”, “_blank”);
    }

    /**
    * Utility function to wrap up changing pages. Avoids over-aggressive popup blockers.
    * @param url The URL to change to. Either a String or a URLRequest
    * @param window The target browser window/tab, generally _self, _top, or _blank
    * @usage URLNavigator.ChangePage(“http://www.google.com”, “_blank”);
    */
    public static function ChangePage(url:*, window:String = “_self”):void {
    var req:URLRequest = url is String ? new URLRequest(url) : url;
    if (!ExternalInterface.available) {
    navigateToURL(req, window);
    } else {
    var strUserAgent:String = String(ExternalInterface.call(“function() {return navigator.userAgent;}”)).toLowerCase();
    if (strUserAgent.indexOf(“firefox”) != -1 || (strUserAgent.indexOf(“msie”) != -1 && uint(strUserAgent.substr(strUserAgent.indexOf(“msie”) + 5, 3)) >= 7)) {
    ExternalInterface.call(“window.open”, req.url, window);
    } else {
    navigateToURL(req, window);
    }
    }
    }

    }
    }

  96. works perfectly! Thank a lot!

  97. Thanks for the helpful post. This worked just like I thought it would. I look forward to reading more from you in the future.

  98. musicservice says:

    This works great. I modified per your previous post the .as file to control window properties. The only issue I’m having is with Safari 4. Just opens a new window/tab. Any thoughts about this?

  99. I’m having trouble with making this work.
    Can’t anybody upload a complete map? With the .fla, the .swf and the .html?
    Maybe i can find my solution to make this baby run!

  100. @musicservice: Yes, my thoughts are that Safari is probably the worst browser on earth. Can you control window positioning at all in Safari? I didn’t think you could.

    @Wessiez: there’s nothing really to the integration. You just stick it in the right folder and call a function. That’s it!

  101. [...] leider auch nicht. Ein anderen Ansatz kann man hier finden: Popups Blocked in AS3 with navigateToURL() | Zorked! [...]

  102. [...] zum Artikel « vorheriger Eintrag 14. Dezember 2009 (12:21 Uhr) – flash & flex, jquery & [...]

  103. Hi, works like a charm!!!
    very nice.

    I have a questiong though.
    I have set my browser to open all new windows in a new tab and when i call URLNavigator it opens, as expected, in a new tab in the existing window.
    is it possible to go around this problem?

  104. Never mind.
    It open in a new window when i run the flash on the web instead of Flash CS4.

    As I said before. works great. :)

  105. Thanks very much – that works great for me. You’ve been extremely helpful!

  106. It doesn’t work. The browser Firefox opens a new tab when I click on the link.

    This is the code:


    import com.zorked.URLNavigator;

    ...

    function callLink(e:MouseEvent):void
    {
    URLNavigator.ChangePage("http://www.holidaymedia.nl", "_blank");
    }
    mHMlink.addEventListener(MouseEvent.CLICK, callLink);
    mHMlink.buttonMode = true;


    /**
    * Flash AS3 Page Change Utility
    * @author Jordan Ambra
    * @version 1.2
    * http://www.zorked.com
    * http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/
    */

    package com.zorked {
    import flash.external.ExternalInterface;
    import flash.net.*;

    public class URLNavigator {

    /**
    * Utility function to wrap up changing pages. Avoids over-aggressive popup blockers.
    * @param url The URL to change to. Either a String or a URLRequest
    * @param window The target browser window/tab, generally _self, _top, or _blank
    * @usage URLNavigator.ChangePage("http://www.google.com", "_blank");
    */
    public static function ChangePage(url:*, window:String = "_self"):void {
    var req:URLRequest = url is String ? new URLRequest(url) : url;
    if (!ExternalInterface.available) {
    navigateToURL(req, window);
    } else {
    var strUserAgent:String = String(ExternalInterface.call("function() {return navigator.userAgent;}")).toLowerCase();
    if (strUserAgent.indexOf("firefox") != -1 || (strUserAgent.indexOf("msie") != -1 && uint(strUserAgent.substr(strUserAgent.indexOf("msie") + 5, 3)) >= 7)) {
    ExternalInterface.call("window.open", req.url, window);
    } else {
    navigateToURL(req, window);
    }
    }
    }

    }

    }

  107. Hi Roy, generally Firefox will open in a new window but if you have the setting to open new windows as tabs, it will of course do that.

    Your code and implementation is correct.

  108. Ok, but how can make flash to open a real pop-up window like you do it in html:
    Design & Realisatie: Holiday Media

    This html code that calls a javascript function will open the pop-up in all the browsers.

    But….
    If do this in as3, this would be the code:
    function openPopUp(evt:MouseEvent):void {
    navigateToURL(js,”_self” );
    }
    var js:URLRequest=new URLRequest();
    js.url = “javascript:window.open(‘http://www.holidaymedia.nl/webdesign-holidaymedia.htm’, ‘hm’,’status=no,scrollbars=no,resizable=no,width=350,height=210,left=80,top=180′);newWindow.focus(); void(0);”;

    mHMlink.addEventListener(MouseEvent.CLICK,openPopUp);
    mHMlink.buttonMode = true;

    That works perfect in FF, Chrome, safari, etc. But in IE it will block the pop-up.
    How can I work around this.

    Greetz

  109. Here the html code for the pop-up but then in plain text:
    a href=”http://www.holidaymedia.nl/promo/popup_madeby.htm” onclick=”window.open(”,’hm’,’scrollbars=no,resizable=no,width=350,height=210′);” target=”hm” class=”webdesign”>Design & Realisatie: Holiday Media</a

  110. Ok, I found a solution and it worked great. With this code AS3:

    mHMlink.addEventListener(MouseEvent.CLICK,openPopUp);

    function openPopUp(evt:MouseEvent):void {
    var url:String = "http://www.holidaymedia.nl/webdesign-holidaymedia.htm";
    var windowName:String = "hm";
    var windowOptions:String = "width=350,height=210,left=80,top=180";
    ExternalInterface.call( "window.open", url, windowName, windowOptions );
    }

    This code it works in all browsers including IE

  111. How does this fit into the Jordan’s code?

  112. i’m still wondering how to use Roy’s code in Jordan’s script- i want to specify the size of the browser window.
    thanks e

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>