United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7063746 applet.onLoad is called multiple times in IE
JDK-7063746 : applet.onLoad is called multiple times in IE

Details
Type:
Bug
Submit Date:
2011-07-07
Status:
Resolved
Updated Date:
2011-09-22
Project Name:
JDK
Resolved Date:
2011-09-06
Component:
deploy
OS:
generic
Sub-Component:
plugin
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7-client
Fixed Versions:
7u2 (b04)

Related Reports
Backport:

Sub Tasks

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.
                                     
2011-08-26



Hardware and Software, Engineered to Work Together