By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Accessing variables between frames

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a


Frédéric Mayot wrote:
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)


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

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
> 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 ?
Jul 20 '05 #3

P: n/a


Frédéric Mayot wrote:
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.


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

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

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4

P: n/a
> 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 ;-(
Jul 20 '05 #5

P: n/a


Frédéric Mayot wrote:
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.
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 ;-(


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/j...eVariable.html
The variable access works with IE4+, Netscape 6+, Mozilla, Opera 7
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #6

P: n/a
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
Jul 20 '05 #7

P: n/a
@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 ... !
Jul 20 '05 #8

P: n/a


Frédéric Mayot wrote:
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?

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.