0 Replies Latest reply on Aug 3, 2010 10:48 AM by DZMD

    Trouble detecting browser close in Internet Explorer

    DZMD

      Please help!

       

      I'm trying to detect when the browser closes (or tab closes, or page reloads, etc.) so that I can save user information. I've followed the advice of others on the web, and have it working with Firefox, but not IE. The code in my wrapper is below, which attempts to get access to the embedded swf object a variety of ways to presumably handle multiple browsers. PLEASE HELP!

       

      //  Function to get a reference to the embedded swf file

                          function getFlashMovieObject(movieName)
                          {
                            if (window.document[movieName])
                            {
                                return window.document[movieName];
                            }
                            if (navigator.appName.indexOf("Microsoft Internet") == -1)
                            {
                              if (document.embeds && document.embeds[movieName])
                                return document.embeds[movieName];
                            }
                            else // if (navigator.appName.indexOf("Microsoft Internet") != -1)
                            {
                              return document.getElementById(movieName);
                            }    
                          }              

       

      Here's the code that calls this function:

                          window.onbeforeunload = function() 
                          { 
                              var myApp = getFlashMovieObject("MySwf");
                              return myApp.onCloseApplication();

                          }

       

      Here's the code that embeds the swf:

                        var flashVars = {};
                        var strHref = window.location.href;
                        if ( strHref.indexOf("?") > -1 )
                        {
                              var strQueryString = strHref.substr(strHref.indexOf("?")+1);
                              var aQueryString = strQueryString.split("&");
                              for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
                              {
                                  var aParam = aQueryString[iParam].split("=");
                                  flashVars[aParam[0]] = aParam[1];
                              }
                        }
                      var params = {};
                      params.quality = "high";
                      params.bgcolor = "#ffffff";
                      params.allowscriptaccess = "sameDomain";
                      var attributes = {};
                      attributes.id = "MySwf";
                      attributes.name = "MySwf";
                      attributes.align = "middle";

       

                        //create your instance of your SWF
                        swfobject.embedSWF("MySwf.swf", "flashContent", "100%", "100%", "10.0.0", "expressInstall.swf",
                          flashVars, params,attributes);