<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.22883-</id>
  <updated>2009-11-16T15:54:38Z</updated>
  <title>Comments for Quick Flex Tip:  Detecting PopUp Blockers (http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.22883</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=22883" title="Quick Flex Tip:  Detecting PopUp Blockers" />
    <published>2008-02-12T17:25:54Z</published>
    <updated>2008-02-12T16:02:07Z</updated>
    <title>Quick Flex Tip:  Detecting PopUp Blockers</title>
    <summary>Just about every application at some time or another needs to launch a new window... Its easy enough to open a new window.  In flex, you can just use the navigateToURL window, but that has limitations.  </summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<div class="ap_r_front"  style="margin: 0px 14px; 14px; 14px;"><a href="http://www.insideria.com/upload/2008/02/quick_flex_tip_detecting_popup/flex-icon.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/02/quick_flex_tip_detecting_popup/flex-icon.png" alt="flex-icon.png" title="Click to enlarge" width="148"/></a></div>

<p>Just about every application at some time or another needs to launch a new window... Its easy enough to open a new window.  In flex, you can just use the navigateToURL window, but that has limitations.   Nearly every browser now has a popup blocker on it.   Unfortunately, navigateToURL fails silently when blocked by a popup blocker.  Your browser might display an error message when the popup is blocked, but there is no way to know this within your application.</p>

<p>Well, with a small chunk of JavaScript, and ExternalInterface, you can detect when popup windows get blocked.   Basically, instead of using navigateToUrl to launch a new window, you delegate this action to JavaScript's window.open function. </p>

<p>Whenever you use window.open, the open function will return a reference to the window that you just opened.  If that reference is null, you know that the popup was blocked.   Some browsers and popup blockers handle things slightly differently, so I also add a try/catch around the window.open function call.  This way you can catch any errors opening the window.  If the window opened correctly, have the JavaScript function return true to the Flex application.  If it did not display correctly, have it return false to the Flex application.</p>

<p>Here's an example JavaScript function:</p>

<pre>function openURL( url, target )
{
	try
	{
		var popup = window.open( url, target );
		if ( popup == null )
			return false;

<p>		if ( window.opera )<br />
			if (!popup.opera)<br />
				return false;<br />
	}<br />
	catch(err)<br />
	{<br />
		return false;<br />
	}<br />
	return true;<br />
}<br />
</pre></p>

<p>Now, in ActionScript you just need to invoke this function using ExternalInterface.   Here's an example how:</p>

<pre>public class URLUtil
{
	public static function openPopUp( url : String, target : String="_blank" ) : void
	{
		var success : Boolean = ExternalInterface.call( "openURL", url, target );
		if ( !success )
			Alert.show( "Request blocked.", "Error" );
	}
}</pre>

<p>Notice that I am using the result of the ExternalInterface.call method to determine if the window opened correctly.   If it returned false, then it didn't open correctly, and an Alert message is shown.</p>

<p>You can test it out for yourself here:  </p>

<p><iframe width="100%" height="150" src="http://www.cynergysystems.com/blogs/blogs/andrew.trice/popups/main.html" ></iframe></p>

<p><i>Note:  You will need to disable popups for this site in order to see what happens when the popup is blocked. I've only tested this with IE7 and FireFox on Windows.  Let me know if it fails on anything. :-) </i></p>

<p>This just goes to show you that its not always Flex vs. JavaScript.  In order to achieve optimum results, you often need both.</p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2015071</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2015071" />
    <title>Comment from zedia.net on 2008-02-12</title>
    <author>
        <name>zedia.net</name>
        <uri>http://www.zedia.net</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.zedia.net">
        <![CDATA[<p>I'm using Opera on Windows; the pop-up is blocked, but Flex doesn't show the alert... I hope this helps</p>]]>
    </content>
    <published>2008-02-12T15:28:22Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2015076</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2015076" />
    <title>Comment from Andrew Trice on 2008-02-12</title>
    <author>
        <name>Andrew Trice</name>
        <uri>http://www.tricedesigns.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.tricedesigns.com">
        <![CDATA[<p>Thanks for pointing that out!  I just posted some updated code that now works in opera.  <br />
-Andy</p>]]>
    </content>
    <published>2008-02-12T16:04:33Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2015087</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2015087" />
    <title>Comment from alimills on 2008-02-12</title>
    <author>
        <name>alimills</name>
        <uri>http://www.asserttrue.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.asserttrue.com">
        <![CDATA[<p>Andrew,</p>

<p>Popup handling in Mac/Safari works the opposite way than one would expect.  Where as most browsers block navigateToUrl and allow JS window.open calls, Safari does just the opposite.  Due to this flip-flopped behavior, the above example doesn't work in Safari.  The way to work around the conflicting browser handling and get consistent behavior is:</p>

<p>1. use ExternalInterface.addCallback to register an AS function that calls navigateToUrl() with a target of “_blank”</p>

<p>2. as first pass, try the ExternalInterface.call to JavaScript to window.open path</p>

<p>3. call the the registered AS navigateToUrl() function if window.open returns null</p>

<p>I wrote a blog post, complete with code and all, about this process a while ago titled, "Workaround for Safari Blocking Flash Initiated Pop Ups".  Feel free to check it out at <a href="http://www.asserttrue.com/articles/2007/08/22/workaround-for-safari-blocking-flash-initiated-pop-ups">http://www.asserttrue.com/articles/2007/08/22/workaround-for-safari-blocking-flash-initiated-pop-ups</a></p>

<p><br />
Ali</p>]]>
    </content>
    <published>2008-02-12T17:38:37Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2015159</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2015159" />
    <title>Comment from Jason The Saj on 2008-02-13</title>
    <author>
        <name>Jason The Saj</name>
        <uri>http://thesaj.wordpress.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://thesaj.wordpress.com">
        <![CDATA[<p>I've been dealing with this issue (and others for a while).</p>

<p>I've finally come to a working model that appears to work on XP (IE6, Firefox, Safari 3, Opera) & OSX (Firefox, Safari 3, Safari 2). The only caveat being that the use of wmode="transparent" causes IE to pop-up block.</p>

<p><a href="http://thesaj.wordpress.com/2008/02/12/the-nightmare-that-is-_blank-part-ii-help/">http://thesaj.wordpress.com/2008/02/12/the-nightmare-that-is-_blank-part-ii-help/</a></p>

<p>Your implementation is quite different from mine. I am curious if there are any advantages and/or disadvantages between the two? Anything I might have missed...</p>

<p>- Jason The Saj</p>

<p>PS - it seems to take multiple tries to pass your captcha.</p>]]>
    </content>
    <published>2008-02-13T20:29:46Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2016204</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2016204" />
    <title>Comment from garag on 2008-03-28</title>
    <author>
        <name>garag</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Andrew,</p>

<p>probably this is a stupid question...</p>

<p>Where I have to put the js function? In a specific file? I tried to put it in the js file that flex has generated, AC_OETags.js, but it doesn't work...</p>

<p>Any suggestion?</p>

<p>Thank you very much</p>]]>
    </content>
    <published>2008-03-28T22:41:33Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2016606</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2016606" />
    <title>Comment from sudheer on 2008-04-16</title>
    <author>
        <name>sudheer</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi,</p>

<p>All the above workarounds work fine when u have access to the html wrapper.</p>

<p>I have a slightly different problem, i've made a widget using flex and embedded it in facebook, i need to popout a window from that widget, if the users browser has a popupblocker then  my popup would never popout and also the widget would never know that.</p>

<p>Since i dont have access to the facebook html page in which i embed my widget i can use window.open.</p>

<p><br />
Any workaround for this????</p>

<p><br />
Thanks in advance<br />
sudheer<br />
</p>]]>
    </content>
    <published>2008-04-16T07:36:54Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2045245</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2045245" />
    <title>Comment from Alex on 2008-10-30</title>
    <author>
        <name>Alex</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Doesn't work on Windows XP, FireFox 3... fyi.</p>

<p>Alex</p>]]>
    </content>
    <published>2008-10-31T02:26:43Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152775</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152775" />
    <title>Comment from Taylan on 2009-10-23</title>
    <author>
        <name>Taylan</name>
        <uri>http://www.taylan.gen.tr</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.taylan.gen.tr">
        <![CDATA[<p>Alex says right.It doesn't work on windows xp(firefox 3.5)</p>]]>
    </content>
    <published>2009-10-23T20:31:52Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152778</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152778" />
    <title>Comment from Serdar on 2009-10-23</title>
    <author>
        <name>Serdar</name>
        <uri>http://www.anzele.net</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.anzele.net">
        <![CDATA[<p>Thanks for pointing that out! I just posted some updated code that now works in opera. </p>]]>
    </content>
    <published>2009-10-23T20:34:37Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152787</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152787" />
    <title>Comment from Diyet on 2009-10-23</title>
    <author>
        <name>Diyet</name>
        <uri>http://www.diyetmutfagi.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.diyetmutfagi.com">
        <![CDATA[<p>it doesnt on firefox i checked it.. i think that script does not work on xp or firefox..<br />
am i wrong?</p>]]>
    </content>
    <published>2009-10-23T20:39:14Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152794</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152794" />
    <title>Comment from dizi izle on 2009-10-23</title>
    <author>
        <name>dizi izle</name>
        <uri>http://www.sanaldizi.net</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.sanaldizi.net">
        <![CDATA[<p>You should still use a small timeout to allow slower machines time to launch the window. You may get some false negatives otherwise.</p>]]>
    </content>
    <published>2009-10-23T20:43:03Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152802</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152802" />
    <title>Comment from Erbil on 2009-10-23</title>
    <author>
        <name>Erbil</name>
        <uri>http://www.erbiloner.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.erbiloner.com">
        <![CDATA[<p>Doesn't work on ie6 and firefox 3.5 :( thank you </p>]]>
    </content>
    <published>2009-10-23T20:46:13Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152815</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152815" />
    <title>Comment from ChaO on 2009-10-23</title>
    <author>
        <name>ChaO</name>
        <uri>http://www.bilgimekani.net</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.bilgimekani.net">
        <![CDATA[<p>Thanks for pointing that out! I just posted some updated code that now works in opera.</p>]]>
    </content>
    <published>2009-10-23T20:58:27Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.22883-comment:2152816</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.22883" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/02/quick-flex-tip-detecting-popup.html#comment-2152816" />
    <title>Comment from Modifiyeli Arabalar on 2009-10-23</title>
    <author>
        <name>Modifiyeli Arabalar</name>
        <uri>http://www.tuning53.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.tuning53.com">
        <![CDATA[<p>No gays. That worked on my PC.</p>]]>
    </content>
    <published>2009-10-23T20:58:46Z</published>
  </entry>

</feed
