0 Replies Latest reply on Mar 29, 2008 9:19 AM by suds123

    Clean up Flex app upon brower close

    suds123
      Hi,
      This is more of a browser question than Flex specific. However, since it is related, I thought of posting this question here. When the user closes the browser, I like to clean up the flex application i.e. invalidate the sessions, log user activity in a database. After some research, I figured out that both onbeforeunload and onunload methods are necessary to implement it. I couldn't find a way to capture the "CANCEL" event from the user from onbeforeunload method. User may click "OK" to navigate away or "CANCEL" to stay in the flex application. Hence, I can't put my wrapup() methods inside onbeforeunload . For that, I use onunload event.

      Everything works fine except when I try to close the Firefox tab. Firefox calls onbeforeunload, but doesn't call the onunload. Has anyone come across this problem ? Could you be kind enough to post your solution ?

      window.onbeforeunload = function() {

      var warning = "";
      var fxControl = document.flexclient || window.flexclient;
      if (typeof fxControl.getUnsavedDataWarning == "function") {
      warning = fxControl.getUnsavedDataWarning();
      }

      if (warning != "")
      return warning;
      else
      return;

      }

      window.onunload = function(){

      var fxControl = document.flexclient || window.flexclient;

      if (typeof fxControl.wrapupUser == "function") {
      var result = fxControl.wrapupUser();
      alert(result);
      }
      }

      Regards,
      Sudhansu Pati
      BEA Systems