JDK-7063746 : applet.onLoad is called multiple times in IE
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 7-client
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-07-07
  • Updated: 2011-09-22
  • Resolved: 2011-09-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u2 b04Fixed 8Fixed
Description
onLoad callback is called twice in IE (and once in FF). 
Perhaps same problem s applicable to other callbacks too.
This is annoying as developer need to make keep state in his code to detetc if callback was called already.

Here is sample html page to reproduce the problem using Fish sample from JavaFX:

��<html><head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script>
            var READY = 2; 
            function callApplet() {
               var a = document.getElementById("my");
               try { // try/catch is not needed for JavaFX applet
                 if (a.status < READY)  {
                   //applet not ready, register itself                 
                   a.onLoad = callApplet;
                   log("A: status = "+a.status);
                   return;
                 }
                 log("B: status = "+a.status);
               } catch(err) {window.alert("OOO");} //JRE6 or earlier and no JavaFX

               //either applet is ready or nonblocking access is not supported
               log("C: call it!");
            }

            function log(msg) {
               var a = document.getElementById("log");
               var p = document.createElement("p");
               p.appendChild(document.createTextNode(msg));
               a.appendChild(p);
            }

            var deployJava = {
               perfLog: function() {},
               hideSplash: function() {}
            }
        </script>
    </head>
    <body onload="callApplet()">
      Log: <br>
      <div id="log"></div>

<APPLET id="my" style="LEFT: 0px" height="200" width="300" code="dummy.class"><PARAM value="Fish.jnlp" name="jnlp_href" /><PARAM value="true" name="java_status_events" /><PARAM value="application/x-java-applet" name="type" /><PARAM value="2.0+" name="javafx_version" /><PARAM value="true" name="separate_jvm" /><PARAM value="my" name="javafx_applet_id" /><PARAM value="true" name="scriptable" /><PARAM value="-Djnlp.fx.perf=true" name="java_arguments" /></APPLET>


</body></html>
==============

Problem is reproducible if you see following log:

��A: status = 1

B: status = 2

C: call it!

B: status = 2

C: call it!

Comments
EVALUATION With the Fish.html fx demo with preloader, the StartAppletAckMessage is being sent twice from client vm to server vm. That's why we're sending startup status=2 twice to javascript. Perhaps we shouldn't send StartAppletAckMessage for the preloader. Simple fix is not to send duplicate startup status from AxControl to javascript. Similar logic is already in MozPluginInstance. That's why problem isn't reproducible with FF.
26-08-2011