Functioanlity call is not working in window.onbeforeunload


I am doing an application which is using Flex UI and java . I calling the swf as an object embeded in jsp. I want to do a functionality call will I do a browser close.
This functionality was already I have implemented in a button call. So I want to make the javascript to poin to the flex function which is doing this. I have implementd as below,

window.onbeforeunload = function() {

		return "";

and ExternalInterface.addCallback(“cancelFunction”,cancelFunc);

This call to flex functon is working fine for me…
The issue is due to the return statment I am getting an confirm alert asking are you sure to navigate away from thiis page… The functionality I am doing is cancel transaction function . If the user click OK then every thing is fine. But if he clicks cancel the browser will not get closed but and transaction will also get cancelled which is wrong.
If i remove the return then functionality will not get called as the browser is getting closed before it calls the function.
I tried setimeout also …but it is not possible to call setTimeout in onbeforeunload
Could somebody help me to fix this either through Javascript or flex

Have you tried seeing how things go in the onunload event?

Yes paul … I tried as below,

window.onunload = function() {



But alert itself didn’t come . if I gave only alert , that is coming. If I do a functionality call alert also not coming

It seems that cancelfunction is asynchronous, so you will need to do something to give it time to act.
That could be as simple as checking if you need to cancel anything, and if so, follow the cancelfunction with an alert saying “Transaction cancelled”.