How to wait for the Java applet to finish loading on safari?
This does not work in Safari:
<html>
<body>
<applet id="MyApplet" code="MyAppletClass" archive="MyApplet.jar">
<script type="text/javascript">
alert(document.getElementById('MyApplet').myMethod);
</script>
</body>
</html>
Mymethod is a public method declared in myappletclass
When I first load a page in Safari, it will display an alert before the applet is loaded (so the message box is displayed as undefined) If I refresh the page, the applet is loaded and the alert displays the mymethod() {[native code]} function, as you would expect
Of course, this means that the applet method is not available until it is loaded, but Safari does not prevent JavaScript from running< The same problem occurs with body onload >
What I need is something like < body onappletload = "dosomething()" > How can I solve this problem?
thank you
PS: I'm not sure if it's relevant, but the jar has been signed
Solution
I use a timer that resets and keeps checking multiple times before it gives up
<script language="text/javascript" defer>
function performAppletCode(count) {
var applet = document.getElementById('MyApplet');
if (!applet.myMethod && count > 0) {
setTimeout( function() { performAppletCode( --count ); },2000 );
}
else if (applet.myMethod) {
// use the applet for something
}
else {
alert( 'applet Failed to load' );
}
}
performAppletCode( 10 );
</script>
Note that this assumes that the applet will run in safari I have some examples. One applet needs JAVA 6. Even if you use code similar to the above, you only need to suspend safari I choose to perform browser detection on the server and redirect the user to the error page when the browser does not support applet
