JDK-4684153 : LiveConnect method eval() runs in incorrect context when using frames (IE only)
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.3.1_20,1.4.0,1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    solaris_2.5.1,windows_2000,windows_xp solaris_2.5.1,windows_2000,windows_xp
  • CPU: x86,sparc
  • Submitted: 2002-05-13
  • Updated: 2006-08-10
  • Resolved: 2004-09-20
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 JDK 6
1.4.2_07 b01Fixed 6Fixed
Related Reports
Duplicate :  
Description
Name: gm110360			Date: 05/13/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]


ADDITIONAL OPERATING SYSTEMS :
This bug occours in Internet Explorer 5.x and 6, but not in
Netscape 6/Mozilla.

A DESCRIPTION OF THE PROBLEM :
When using an applet in a frameset, LiveConnect
JSObject.eval() in other
frames than the one containing the applet fails. The script
code is evaluated in the context of the window containing
the applet instead of the one specified.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the following example from the test case below. We have
a frameset of two frames,
the one to the left containing an applet:

|---------------|
|Frame1 |Frame2 |
|       |       |
|Applet |       |
|---------------|

The applet does the following:

JSObject win = JSObject.getWindow(applet);
JSObject parent = (JSObject)win.getMember("parent");
JSObject frame2 = (JSObject)parent.getMember("Frame2");
frame2.eval("document.body.style.backgroundColor='green'");


EXPECTED VERSUS ACTUAL BEHAVIOR :
This is supposed to turn the background to green in Frame2,
but instead Frame1 turns green. If Frame2 contains a
JavaScript method called foo() and you try to do
frame2.eval("foo()") that does not work either, because it
tries to evaluate foo() in Frame1.


This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Place all three files in the same directory.

testcase.html:
BEGIN HTML SOURCE
-------------------
<html>
<frameset cols="50%,50%">
  <frame name="Frame1" src="frame1.html">
  <frame name="Frame2" src="about:blank">
</frameset>
</html>
-------------------
END HTML SOURCE

frame1.html
BEGIN HTML SOURCE
-------------------
<html>
  <body>
    <applet code="Test.class" width=100 height=50 MAYSCRIPT></applet>
  </body>
</html>
-------------------
END HTML SOURCE

Test.java
BEGIN JAVA SOURCE
-------------------
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*
import netscape.javascript.*;

public class Test extends Applet implements ActionListener {
    Button button;

    public void init() {
        button = new Button("Run testcase");
        button.addActionListener(this);
        add(button);
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == button) {
            try {
                JSObject win = JSObject.getWindow(this);
                JSObject parent = (JSObject)win.getMember("parent");
                JSObject frame2 = (JSObject)parent.getMember("Frame2");
                frame2.eval("document.body.style.backgroundColor='green'");
            } catch(Exception ex) { System.err.println("Exception
thrown:"+ex); }
        }
    }
}
-------------------
END JAVA SOURCE

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
There is a workaround that may work in some cases, and that
is to reference the members and methods using the "top"
member that is available to all windows.
frame2.eval("top.Frame2.body.style.backgroundColor='green'")
works, but that's not a good solution and also performs bad
because of the unnecessary lookups of "top" and "Frame2".

This approach starts to get silly when you create JavaScript
objects:

top.Frame2.myObject=new
top.Frame2.MyObject(top.Frame2.MY_CONSTANT,
top.Frame2.document.getElementById('test'));
(Review ID: 146414) 
======================================================================
###@###.### 10/4/04 18:08 GMT

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2_07 1.5.0_01 mustang FIXED IN: 1.4.2_07 1.5.0_01 INTEGRATED IN: 1.4.2_07
02-10-2004

EVALUATION A potential fix has been found. It'll be sent to customer for testing soon. ###@###.### 2004-08-25
25-08-2004

WORK AROUND A workaround has been found (different from the one mentioned in the "Description" section). The workaround is to call a JavaScript function from the applet and do the actual evaluation in the called function. Specifically, in Test.java, one can call a JavaScript function as follows: win.call("changeColor", null); changeColor is implemented as follows in frame1.html: function changeColor() { parent.Frame2.location.href="frame2.html" } frame2.html is just simply setting the background color for that frame: <body bgcolor="#FFFFCC"> I've attached the modified test case (newtest.zip). ###@###.### 2004-07-21
21-07-2004