United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4684153 LiveConnect method eval() runs in incorrect context when using frames (IE only)
JDK-4684153 : LiveConnect method eval() runs in incorrect context when using frames (IE only)

Details
Type:
Bug
Submit Date:
2002-05-13
Status:
Resolved
Updated Date:
2006-08-10
Project Name:
JDK
Resolved Date:
2004-09-20
Component:
deploy
OS:
solaris_2.5.1,windows_xp,windows_2000
Sub-Component:
plugin
CPU:
x86,sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.1_20,1.4.0,1.4.2
Fixed Versions:
1.4.2_07 (b01)

Related Reports
Backport:
Backport:
Duplicate:

Sub Tasks

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
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
                                     
2004-07-21
EVALUATION

A potential fix has been found. It'll be sent to customer for testing soon.
###@###.### 2004-08-25
                                     
2004-08-25
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


                                     
2004-10-02



Hardware and Software, Engineered to Work Together