Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Accessing variables between frames

Reply
Thread Tools

Accessing variables between frames

 
 
Frédéric Mayot
Guest
Posts: n/a
 
      12-20-2003
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



 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-20-2003


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/

 
Reply With Quote
 
 
 
 
Frédéric Mayot
Guest
Posts: n/a
 
      12-20-2003
> 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 ?


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-20-2003


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/

 
Reply With Quote
 
Frédéric Mayot
Guest
Posts: n/a
 
      12-20-2003
> 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 ;-(


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-21-2003


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/

 
Reply With Quote
 
Frédéric Mayot
Guest
Posts: n/a
 
      12-21-2003
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


 
Reply With Quote
 
@SM
Guest
Posts: n/a
 
      12-21-2003


"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 ... !
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-22-2003


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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Need to use "volatile" for accessing variables between threads? Marcel Müller C++ 16 07-28-2009 09:56 AM
Re: Need to use "volatile" for accessing variables between threads? REH C++ 0 07-27-2009 03:09 PM
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Accessing class member variables - properties or variables? dwok Java 7 03-04-2005 03:54 AM
From Frames to no frames? Powerslave2112 HTML 2 01-20-2004 10:30 PM



Advertisments