/    Sign up×
Community /Pin to ProfileBookmark

Want to call a functionality on window.onbeforeunload

Hi,

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() {
getMyApp(“mySwf”).cancelFunction();

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

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @jodha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...