Link to home
Start Free TrialLog in
Avatar of dkilby
dkilbyFlag for Canada

asked on

Flash + Calling Javascript Function

I have a javascript function on the page to give a pop up warning if the user tries to close the browswer or leave the page, i am trying to allow the page to redirect when the flash movie has finished.  when i try calling a function on the page from Flash, the close page warning still comes up 1st.  Below is the code i am using.

<SCRIPT language=javascript>
            
isRedirecting = true;
            
function setRedirectBrowser() {
alert("TEST")
isRedirecting=false;
}
                  
function closeIt() {
alert(isRedirecting);
if (isRedirecting) {
return 'Please save first';
}
}
</SCRIPT>

I have an test alert in setRedirectBrowser so i can see when the function is called, and it is after the closeIt function runs, is there anyway to redirect the browser without the warning popup coming up.

I am using GetURL("Javascript:setRedirectBrowser ()"); in the Flash movie

ASKER CERTIFIED SOLUTION
Avatar of negatyve
negatyve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkilby

ASKER

yes i have

<body onunload="closeIt()">
Avatar of negatyve
negatyve

Is my script working? Have you tested it?
Avatar of dkilby

ASKER

i tested the script and it is not quite what i am looking for, 1st i need to use onbeforeunload not onunload as i am trying to stop the user from closing the browser, if i use the above code the alert box comes up the user clicks OK the browser still closes, i also tried the above code with onbeforeunload when the flash movie finishes the closeIt function runs first then the setRedirectBrowser, i put an alert in the setRedirectBrowser to see at when it runs.

I tried to get the answer in Javascript section, but it seems now the issue is with Flash as it posts back to the page the page tries to reload and the closeIt function fires, instead of the setRedirectBrowser first, below is the link to Javascript question for background.

Thanks for the help

https://www.experts-exchange.com/questions/21478805/Javascript-onbeforeunload-popup-on-page-exit.html
Could you write here the complete html code? (I mean, only the part related to javascript, no content)
Avatar of dkilby

ASKER

in Flash at the end of the movie i need it to pass some variables to another page so this is the code i have in Flash

            getURL("javascript:setRedirectBrowser()");
            //getURL("data_transfer.aspx", "_self", "POST");  

I have the passing of variables commented out right now to try and figure out the calling of the javascript function

In the page that holds the flash movie, all i have is the below code

<html>
      <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <title>Test</title>
            
            
          <script language="javascript">
          <!--
               isRedirecting = true;
               function setRedirectBrowser()
               {
                    isRedirecting=false;
                    alert(isRedirecting)
               }
               function closeIt()
               {
                    if (isRedirecting) {
                         alert('Please save first');
                         return false;
                    }
               }
          //-->
          </script>

            
            <style type="text/css">
                  <!--
                  body {
                        margin-left: 0px;
                        margin-top: 0px;
                        margin-right: 0px;
                        margin-bottom: 0px;
                  }
            --></style>
      </head>
      <BODY onbeforeunload="closeIt()">
      <button id="closeWindow" onclick="setRedirectBrowser();">Click Here</button>
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="600" height="600" ID="Shockwaveflash1" VIEWASTEXT>
                  <param name="movie" value="<%Response.Write (FileName)%>">
                  <param name="quality" value="high">
                  <embed src="<%Response.Write (FileName)%>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="600"></embed>
            </object>
      </body>
</html>
Avatar of dkilby

ASKER

ok found something that works.

function closeIT(){
     if (event.clientY < 0)
         event.returnValue = 'Are you sure you want to Quit?'
   }
}

this does what i need, if the user trys closing the browser using the 'X' the warning comes, but at the end of the flash movie the page is able to redirect.

Thanks for the help
Avatar of dkilby

ASKER

ok found something that works.

function closeIT(){
     if (event.clientY < 0)
         event.returnValue = 'Are you sure you want to Quit?'
   }
}

this does what i need, if the user trys closing the browser using the 'X' the warning comes, but at the end of the flash movie the page is able to redirect.

Thanks for the help, i will split the points as you both where a lot of help.