<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alekkus » Empowering social media with Flash &#187; browser</title>
	<atom:link href="http://alekkus.com/blog/tag/browser/feed/" rel="self" type="application/rss+xml" />
	<link>http://alekkus.com/blog</link>
	<description>flex consultant + social media specialist</description>
	<lastBuildDate>Wed, 17 Mar 2010 07:54:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex tutorial: Popup warning before browser closes</title>
		<link>http://alekkus.com/blog/2009/02/flex-tutorial-popup-warning-before-browser-closes/</link>
		<comments>http://alekkus.com/blog/2009/02/flex-tutorial-popup-warning-before-browser-closes/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 07:10:40 +0000</pubDate>
		<dc:creator>Alekkus</dc:creator>
				<category><![CDATA[Flex 3 (Moxie)]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://alekkus.com/blog/?p=166</guid>
		<description><![CDATA[As the title implies, this post will show you how to ask for user confirmation before the browser window closes or navigated away from the current url.
We will make use of the onbeforeunload event in javascript. So first of all, you will need to insert the following into index.template.html.


&#60;script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34;&#62;
window.onbeforeunload = function()
{
	var swfApp = [...]]]></description>
			<content:encoded><![CDATA[<p>As the title implies, this post will show you how to ask for user confirmation before the browser window closes or navigated away from the current url.</p>
<p>We will make use of the <em>onbeforeunload</em> event in javascript. So first of all, you will need to insert the following into <em>index.template.html</em>.</p>
<pre name="code" class="html">

&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;
window.onbeforeunload = function()
{
	var swfApp = ${application};

	return swfApp.onCloseApplication();
}
&lt;/script&gt;
</pre>
<p>The all you need is to add a callback function <em>onCloseApplication</em> in your main application (see codes below).</p>
<p><strong>Demo:</strong><br />
<a href="http://alekkus.com/flex3/exit_warning.html">Application Exit Warning</a> (view source enabled)</p>
<p><strong>Source Codes: main application</strong></p>
<pre name="code" class="as3">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application
	xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;absolute&quot;
	backgroundColor=&quot;#F8F8F8&quot;
	creationComplete=&quot;onCreationComplete()&quot;&gt;

&lt;mx:Script&gt;
&lt;![CDATA[
	private function onCreationComplete() : void
	{
		if ( ExternalInterface.available )
		{
			ExternalInterface.addCallback( &quot;onCloseApplication&quot;,
				function():String
				{
					if ( chkDisplayMessage.selected )
					{
						return txtMsg.text;
					}
					return null;
				} );
		}
	}
]]&gt;
&lt;/mx:Script&gt;

	&lt;mx:CheckBox
		id=&quot;chkDisplayMessage&quot;
		x=&quot;37&quot; y=&quot;29&quot;
		label=&quot;Display message upon application exit&quot;/&gt;

	&lt;mx:Label x=&quot;37&quot; y=&quot;59&quot; text=&quot;Message:&quot;/&gt;

	&lt;mx:TextInput
		id=&quot;txtMsg&quot;
		x=&quot;104&quot; y=&quot;57&quot;
		text=&quot;Please don&#039;t close me.&quot;/&gt;

	&lt;mx:Label x=&quot;37&quot; y=&quot;107&quot; color=&quot;#666666&quot; text=&quot;*Check on the above checkbox, then close/navigate away from the current url.&quot;/&gt;
&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://alekkus.com/blog/2009/02/flex-tutorial-popup-warning-before-browser-closes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
