Accessing variables between frames

F

Frédéric Mayot

Hi,

I have an HTML page like this :

--- test.html
<html>
<body>
<form>
<iframe id="frametest" name="frametest" src="iframe.html"></iframe>
<select multiple ondblclick="alert(frametest.v);"></select>
</form>
</body>
</html>
---

and another one :

--- iframe.html
<script>var v = 2;</script>
---

I can retrieve 'v' with IE6 but not with mozilla (firebird 0.7)

Thanks.

Fred
 
M

Martin Honnen

Frédéric Mayot said:
I have an HTML page like this :

--- test.html
<html>
<body>
<form>
<iframe id="frametest" name="frametest" src="iframe.html"></iframe>
<select multiple ondblclick="alert(frametest.v);"></select>
</form>
</body>
</html>
---

and another one :

--- iframe.html
<script>var v = 2;</script>

Make sure you have
<iframe name="frametest" ...>
then access the frame as
var frame = window.frames.frametest;
then any variables as
frame.variablename
that works with IE4+, Netscape 6+, Mozilla, Opera
 
F

Frédéric Mayot

Make sure you have
<iframe name="frametest" ...>
then access the frame as
var frame = window.frames.frametest;
then any variables as
frame.variablename
that works with IE4+, Netscape 6+, Mozilla, Opera

Sorry, but if I replace

alert(frametest.v);

with

alert(window.frames.frametest.v);

in the code I posted, it doesn't work with mozilla (it's still fine with
IE6).
typeof(window.frames.frametest) indicates 'object window', but the v
variable is unknown.
Any idea ?
 
M

Martin Honnen

Frédéric Mayot said:
Sorry, but if I replace

alert(frametest.v);

with

alert(window.frames.frametest.v);

in the code I posted, it doesn't work with mozilla (it's still fine with
IE6).
typeof(window.frames.frametest) indicates 'object window', but the v
variable is unknown.

I don't think that typeof ever yields 'object window'.

Make a test case and post a URL if it doesn't work
 
F

Frédéric Mayot

I don't think that typeof ever yields 'object window'.

Mozilla (firebird) returned '[object Window]' on
alert(window.frames.frametest);
Make a test case and post a URL if it doesn't work

I've already posted my test case..., it's in my first message ;-(
 
M

Martin Honnen

Frédéric Mayot said:
I don't think that typeof ever yields 'object window'.


Mozilla (firebird) returned '[object Window]' on
alert(window.frames.frametest);

Yes, but that is not the result of typeof as you claimed earlier.
I've already posted my test case..., it's in my first message ;-(

Well, you got suggestions what to use to script the iframe cross
browser, use them and I am sure it works, if not you have done something
wrong but we can only find errors if you care to show your changed code.
Here is an example using my suggestion:
http://home.arcor.de/martin.honnen/javascript/200312/accessingIframeVariable.html
The variable access works with IE4+, Netscape 6+, Mozilla, Opera 7
 
F

Frédéric Mayot

Well, I tried your code on my local machine, and it doesn't work. I tried
with my web server and it works. I don't understand why mozilla doesn't
allow this behavior : I thought it was (like IE) only when the domains (URL)
between the frame and the parent window were different.

Thanks for your help.

Fred
 
@

@SM

"Frédéric Mayot" a ecrit :
Well, I tried your code on my local machine, and it doesn't work.

with (allmost) your original code :

--- test.html
<html>
<body>
<iframe id="frametest" name="frametest" src="iframe.html"></iframe>
<form>
<input type=button onclick="alert(parent.frametest.v);" value="To see">
</form>
</body>
</html>
---

Works fine on my Mac (system 8.6) with :
- IE 5.0
- Mozilla 1.2
- Opera 6.03
- iCab 2.95

Notice :
iframe is no more in form, because iCab doesn't love that
with other browsers it's not important
NC4.5 doesn't know iframes ... !
 
M

Martin Honnen

Frédéric Mayot said:
Well, I tried your code on my local machine, and it doesn't work. I tried
with my web server and it works. I don't understand why mozilla doesn't
allow this behavior : I thought it was (like IE) only when the domains (URL)
between the frame and the parent window were different.

If both frames are loaded either from the same server or both from a
file: URL then I the example works.
What is happening "when it doesn't work on the local machine", are you
getting any error message in the JavaScript console?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top