SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    functioanlity call is not working in 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

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jodha View Post
    If i remove the return then functionality will not get called as the browser is getting closed before it calls the function.
    Have you tried seeing how things go in the onunload event?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Yes paul ... I tried as below,

    window.onunload = function() {
    getMyApp("mySwf").cancelFunction();

    alert("hi");


    }

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

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jodha View Post
    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".
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •