views:

292

answers:

3

Hi all,

I have the following code in page1.php :

<a href="page2.php" onClick="javascript:callFlash();">Go to page</a>

This calls a function in a Flash movie on page1.php and opens page2.php.

My question is this:

Can I be sure that the flash function will always be called and finish executing before page2.php is called? (The flash function actually saves some data to a local shared object).

Or should I add a bit of code to the flash function to getURL("page2.php"); when it's done.

any thoughts cheers

+2  A: 

If you definitely need the page to open after the flash function is done, then the only way to guarantee that is to redirect from the flash function as you already figured.

Jason Miesionczek
+2  A: 

First of all don’t include "javascript:" pseudo protocol in onclick attribute.

Try using onclick="return callFlash()" — this way, the browser has to wait for the JS function to finish before following the link. I don’t know the method you’re using for calling AS functions, but if it’s synchronous (i.e. can return data to JS without using callbacks or something), then the AS function will finish before JS function, and before page reload. So this should be safe.

Maciej Łebkowski
A: 

The answer to the question is no.

There is an easy workaround. Simply stop the propagation of the click event and let flash do the redirection:

<a href="page2.php" onClick="stop_and_call(event);"/>

the javascript:

function stop_and_call(e)
{
    if (!!(window.attachEvent && !window.opera)){
        // this is IE
        e.returnValue = false;
        e.cancelBubble = true;
    } else {
        e.preventDefault();
        e.stopPropagation();
    }
    e.stopped = true;
    callFlash();
}
Pierre Spring