JDK-5012558 : JSException when APPLET tag is written dynamically to HTML document inside FRAME
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.4.2,1.4.2_03
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-03-12
  • Updated: 2004-07-22
  • Resolved: 2004-04-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.
Other
1.4.2_06 06Fixed
Related Reports
Duplicate :  
Relates :  
Description
This bug appears to be related to bug 4751259, which was fixed in 1.4.1_07 and 1.4.2_02.  The attached test case demonstrates the same behavior as reported in bug 4751259 in all versions prior to the integration of the fix for that bug.  The test case is different from bug 4751259, however, in that the HTML page which writes the APPLET tag dynamically is inside the FRAME of another HTML page.  With 1.4.1_07, 1.4.2_02 - 1.4.2_03, and 1.5.0-beta, running this test case with IE on Windows fails with the error:

"Before call - watch for alert.
the function name is openHTMLTool
document.location.href: http://dtstest15.east:8080/plugintest/mrfrm.htm
JavaScript: Javascript exception
netscape.javascript.JSException: Unknown name.
After call"


There is no problem with Mozilla 1.6 or Netscape 7.1.  The test case output with those browsers is:

"Before call - watch for alert.
the function name is openHTMLTool
document.location.href: http://dtstest15.east:8080/plugintest/mr_ie.htm
After call"

Note the difference in the document.location.href.

There is also no problem with IE on the later plugin versions if the HTML page which writes the APPLET tag dynamically is NOT contained inside a FRAME, or if the HTML page contained inside the frame has the APPLET tag written explicitly inside the HTML instead of being generated dynamically.


Test Case:


mrfrm.htm:
-----------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>I GOT FRAMED.</TITLE>
</HEAD>
<FRAMESET ROWS="90,*" FRAMEBORDER="NO" BORDER=0 FRAMESPACING=0>
<FRAME NAME="MRETOP" SRC="hhh.htm" SCROLLING="NO" MARGINWIDTH=0 MARGINHEIGHT=0 MARGINHEIGHT=0>
<FRAME NAME="MRERIGHT" SRC="mr_ie.htm" SCROLLING="YES" MARGINWIDTH=0 NORESIZE MARGINHEIGHT=0  MARGINHEIGHT=0>
</FRAMESET>
</HTML>
-----------------------------------------------------------------


hhh.htm:
-----------------------------------------------------------------
<HTML>
<title> Top Frame </title>
<body bgcolor=lime>
<h1>I got framed.</h1>
</body>
</HTML>
------------------------------------------------------------------


mr_ie.htm:
------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>Logon to WebFOCUS MRE</TITLE>
<SCRIPT LANGUAGE="JavaScript">

function openHTMLTool()
{ alert("HELLO, I am in the openHTMLTool");   
}

function ibilangtransonload()
{  alert("DEBUG");
   var innerHTML = "<APPLET CODE='PanelTest2.class' MAYSCRIPT NAME='PanelTest2' ID='PanelTest2' HEIGHT=475 WIDTH=700>";
   innerHTML += "</APPLET>";
   document.getElementById("layerDomainAdmin").innerHTML = innerHTML;
   return;
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="ibilangtransonload()">
<DIV ID="layerDomainAdmin" STYLE="display=block"></DIV>
</BODY>
</HTML>
--------------------------------------------------------------------


PanelTest2.java:
--------------------------------------------------------------------
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import netscape.javascript.JSObject;    
import netscape.javascript.JSException; 

public class PanelTest2 extends Applet{
    Vector bloppo = new Vector();
    JavaScript jscript; 
    public void init()
    {
     Button eButton = new Button("GOFORIT");
     Panel center = new Panel();
     center.add(eButton);
     add(center);
     jscript = new JavaScript(this);
     System.out.println("Before call - watch for alert.");
      jscript.call("openHTMLTool",bloppo);
      System.out.println("After call ");
    }
}// end of class
--------------------------------------------------------------------


JavaScript.java:
--------------------------------------------------------------------
import java.applet.Applet;
import java.applet.AppletContext;
import java.util.Vector;
import netscape.javascript.JSObject;
import netscape.javascript.JSException;

public class JavaScript extends Object {
    private Applet applet;
    
    public JavaScript(Applet inApplet) {
       this.applet = inApplet;
    }
  
    public boolean call(String functionName,Vector arguments) {
        String [] args;
        System.out.println("the function name is " + functionName);
        JSObject window=null;
        try {
            window = JSObject.getWindow(applet);
            JSObject doc = (JSObject)window.getMember("document");
            JSObject loc = (JSObject) doc.getMember("location");
            String s = (String)loc.getMember("href");
            System.out.println("document.location.href: " + s);

            if (arguments == null) {
                args=null;   
            }
            else {
                int size=arguments.size();
                args=new String[size];
                for (int index=0;index<size;index++) {
                    args[index]=(String) arguments.elementAt(index);
                }
            }
            window.call(functionName,args);       
        }
        catch (netscape.javascript.JSException ex) {
            System.out.println("Javascript exception");
            ex.printStackTrace();
            return false;
        }
        return true;
    }    
}
----------------------------------------------------------------------



Steps to reproduce:

1.  Place all above files in web server doc root, e.g. C:\Program Files\Apache Group\Apache2\htdocs\plugintest.
2.  Compile Java source. (need to include plugin.jar in classpath)
3.  With 1.4.2_03 JRE installed on system, for example, bring up http://<host:port>/plugintest/mrfrm.htm in IE.  You will see the error in the plugin console.  Netscape and Mozilla will not throw an error.
4.  Now access http://<host:port>/plugintest/mr_ie.htm with IE directly.  You will not see the error.
5.  Now change mr_ie.htm to:

"<HTML>
<HEAD>
<TITLE>Logon to WebFOCUS MRE</TITLE>
<SCRIPT LANGUAGE="JavaScript">

function openHTMLTool()
{ alert("HELLO, I am in the openHTMLTool");   
}


</SCRIPT>
</HEAD>
<BODY>
<APPLET CODE='PanelTest2.class' MAYSCRIPT NAME='PanelTest2' ID='PanelTest2' HEIGHT=475 WIDTH=700>
</APPLET>
</BODY>
</HTML>"

and bring up http://<host:port>/plugintest/mrfrm.htm in IE.  You will not see the error.
###@###.### 2004-03-12
###@###.### 2004-03-25

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2_06 generic tiger-beta2 FIXED IN: 1.4.2_06 tiger-beta2 INTEGRATED IN: 1.4.2_06 tiger-b46 tiger-beta2 VERIFIED IN: 1.4.2_06
23-07-2004

EVALUATION The root cause for this problem is same as that for #4751259. When APPLET tag is generated dynamically, because of IE bug, the plug-in gets activated, de-activated and activated again. The fix for #4751259 was to re-initialize the java side of the applet object to workaround this IE bug. The earlier fix works fine except when the child frame generates the APPLET tag dynamically as well as makes Java->JS call. The dispatch interface to scripting interface obtained during the first activation has the frame's parent context. Therefore when Java->JS call is made, the function is looked up in the wrong place. This problem seems to be fixed if we re-initalize the dispatch interface during second activation ###@###.### 2004-03-16
16-03-2004