Bug 66429 - Cross-access of a JS variable from code in an IFRAME may not work (test case included)
Summary: Cross-access of a JS variable from code in an IFRAME may not work (test case ...
Status: RESOLVED WORKSFORME
Alias: None
Product: konqueror
Classification: Applications
Component: khtml ecma (show other bugs)
Version: unspecified
Platform: RedHat Enterprise Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-23 01:09 UTC by Sebastiano Vigna
Modified: 2004-01-17 14:31 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastiano Vigna 2003-10-23 01:09:29 UTC
Version:            (using KDE KDE 3.1)
Installed from:    RedHat RPMs
OS:          Linux

I develop a framework for database access called ERW (http://erw.dsi.unimi.it/) that use extensively remote scripting. It currently works only with Mozilla and IE, but many users asked for Konqueror/Safari support.

After extensive testing, I came out with the following test case:


--------test.html---------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML><HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<IFRAME NAME="frame" ID="frame" HEIGHT=10></IFRAME>
<SCRIPT TYPE="text/javascript">
RPCframe=document.getElementById("frame")
RPCdone=true
function RPC(s) {
        RPCdone = false
        looseRPC(s)
}
                                                                                                                                             
function looseRPC(s) {
        var RPCdocument=RPCframe.contentDocument ? RPCframe.contentDocument : RPCframe.contentWindow.document
        RPCdocument.location.replace("empty.html")
        RPCdocument.location.replace(s)
}
</SCRIPT>
<INPUT TYPE=BUTTON NAME=RPC VALUE=RPC ONCLICK="RPC('rpc.html')">
<INPUT TYPE=BUTTON NAME=RPCdone VALUE=RPCdone ONCLICK="alert(RPCdone)">
</BODY>
---------------------------------------


----------------rpc.html----------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML><HEAD>
<TITLE>RPC</TITLE>
</HEAD>
<BODY>
<SCRIPT TYPE="text/javascript">
parent.RPCdone=true
</SCRIPT>
</BODY>
------------------------------------------


If you put both files in a directory served by Apache (creating an empty file named empty.html, too), and load test.html, you will see two buttons: RPCdone shows you the value of the JS variable RPCdone, whereas RPC causes an RPC call, that is, RPCdone is set to false, the source of the IFRAME is set to rpc.html, the JS code in rpc.html is executed and RPCdone returns again true. Or, at least, this is what should happen and what happens in Mozilla/IE. With Konqueror (check it out using the RPCdone button) the value of RPCdone alternates between true and false at each call.

This kind of cross-frame variable juggling is absolutely essential in applications heavily based on remote scripting, as some kind of semaphoring is necessary to prevent RPC overlaps. So presently I'm simply stuck.

Ciao,

                                                   seba
Comment 1 Sebastiano Vigna 2004-01-17 14:31:28 UTC
Oops. I discovered this is not really a problem with cross-frame scripting, but with fast calls to replace(). I (stupid me) did not check with the logs that rpc.html was actually being called each the button was pressed, and it isn't. If instead of two consecutive replace I use just one and make the URI unique (e.g., adding a randomly assigned GET variable to the URI) everything works.