TDOT Blog Touchwood Creative

Register | Forgot password?

Author Info

Name
Ben Bishop

Job Title
Senior Interactive Developer



Touchwood is continuing to grow!

We are looking for talented Flex developers to join our Interactive Group. If you have any interest we would love to meet you. Please email your resume to us at:

jobs@touchwoodcreative.com


Flex: How to Detect When the Browser Window Closes

I came across this thread post by blu3 on the FlashKit forums and thought it was too handy to not share on here.

I managed to pull this off and and here comes the solution. First i
declared cleanUp() function in Flex which does the dirty work and
cleans user's leftovers. Then i use ExternalInterface for registering
my cleanUp() function so that i can access it using JavaScript from
.html wrapper:

Code:

import flash.external.ExternalInterface;
ExternalInterface.addCallback("myFlexFunction",cleanUp);
public function cleanUp():void{

//do the dirty work
........................
.........................

}

Then i added following JavaScript function to my .html which embeds Flex application:

Code:

<SCRIPT LANGUAGE="JavaScript">
window.onbeforeunload = clean_up;
function clean_up()
{

var flex = document.${application} || window.${application};
flex.myFlexFunction();

}
</SCRIPT>

And that's it, works in both Firefox and IE when user either closes
browser window or goes to another web page. Alternative solution is
using FABridge or better yet proper session handling

 

Whoa

Glad you like it, best regards :)

blu3

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
© Touchwood Creative 2007 | We use Firefox