Accessing variables between frames

Discussion in 'Javascript' started by Frédéric Mayot, Dec 20, 2003.

  1. 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
    Frédéric Mayot, Dec 20, 2003
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Dec 20, 2003
    #2
    1. Advertising

  3. > 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 ?
    Frédéric Mayot, Dec 20, 2003
    #3
  4. 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/
    Martin Honnen, Dec 20, 2003
    #4
  5. > 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 ;-(
    Frédéric Mayot, Dec 20, 2003
    #5
  6. 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/javascript/200312/accessingIframeVariable.html
    The variable access works with IE4+, Netscape 6+, Mozilla, Opera 7
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 21, 2003
    #6
  7. 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
    Frédéric Mayot, Dec 21, 2003
    #7
  8. Frédéric Mayot

    @SM Guest

    "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 ... !
    @SM, Dec 21, 2003
    #8
  9. 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/
    Martin Honnen, Dec 22, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Powerslave2112

    From Frames to no frames?

    Powerslave2112, Jan 20, 2004, in forum: HTML
    Replies:
    2
    Views:
    580
    brucie
    Jan 20, 2004
  2. Philip
    Replies:
    3
    Views:
    958
    Karl Groves
    Jun 28, 2004
  3. Ale

    Frames or not Frames...

    Ale, Aug 3, 2005, in forum: HTML
    Replies:
    17
    Views:
    952
    Adrienne
    Aug 5, 2005
  4. Replies:
    1
    Views:
    993
    dorayme
    Feb 10, 2006
  5. Replies:
    0
    Views:
    1,198
Loading...

Share This Page