Accessing variables between frames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frédéric Mayot

    Accessing variables between frames

    Hi,

    I have an HTML page like this :

    --- test.html
    <html>
    <body>
    <form>
    <iframe id="frametest" name="frametest " src="iframe.htm l"></iframe>
    <select multiple ondblclick="ale rt(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



  • Martin Honnen

    #2
    Re: Accessing variables between frames



    Frédéric Mayot wrote:
    [color=blue]
    > I have an HTML page like this :
    >
    > --- test.html
    > <html>
    > <body>
    > <form>
    > <iframe id="frametest" name="frametest " src="iframe.htm l"></iframe>
    > <select multiple ondblclick="ale rt(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)[/color]

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

    --

    Martin Honnen


    Comment

    • Frédéric Mayot

      #3
      Re: Accessing variables between frames

      > Make sure you have[color=blue]
      > <iframe name="frametest " ...>
      > then access the frame as
      > var frame = window.frames.f rametest;
      > then any variables as
      > frame.variablen ame
      > that works with IE4+, Netscape 6+, Mozilla, Opera[/color]

      Sorry, but if I replace

      alert(frametest .v);

      with

      alert(window.fr ames.frametest. v);

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


      Comment

      • Martin Honnen

        #4
        Re: Accessing variables between frames



        Frédéric Mayot wrote:
        [color=blue][color=green]
        >>Make sure you have
        >> <iframe name="frametest " ...>
        >>then access the frame as
        >> var frame = window.frames.f rametest;
        >>then any variables as
        >> frame.variablen ame
        >>that works with IE4+, Netscape 6+, Mozilla, Opera[/color]
        >
        >
        > Sorry, but if I replace
        >
        > alert(frametest .v);
        >
        > with
        >
        > alert(window.fr ames.frametest. v);
        >
        > in the code I posted, it doesn't work with mozilla (it's still fine with
        > IE6).
        > typeof(window.f rames.frametest ) indicates 'object window', but the v
        > variable is unknown.[/color]

        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


        Comment

        • Frédéric Mayot

          #5
          Re: Accessing variables between frames

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

          Mozilla (firebird) returned '[object Window]' on
          alert(window.fr ames.frametest) ;
          [color=blue]
          > Make a test case and post a URL if it doesn't work[/color]

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


          Comment

          • Martin Honnen

            #6
            Re: Accessing variables between frames



            Frédéric Mayot wrote:
            [color=blue][color=green]
            >>I don't think that typeof ever yields 'object window'.[/color]
            >
            >
            > Mozilla (firebird) returned '[object Window]' on
            > alert(window.fr ames.frametest) ;[/color]

            Yes, but that is not the result of typeof as you claimed earlier.
            [color=blue][color=green]
            >>Make a test case and post a URL if it doesn't work[/color]
            >
            >
            > I've already posted my test case..., it's in my first message ;-([/color]

            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:

            The variable access works with IE4+, Netscape 6+, Mozilla, Opera 7
            --

            Martin Honnen


            Comment

            • Frédéric Mayot

              #7
              Re: Accessing variables between frames

              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


              Comment

              • @SM

                #8
                Re: Accessing variables between frames



                "Frédéric Mayot" a ecrit :[color=blue]
                >
                > Well, I tried your code on my local machine, and it doesn't work.[/color]

                with (allmost) your original code :

                --- test.html
                <html>
                <body>
                <iframe id="frametest" name="frametest " src="iframe.htm l"></iframe>
                <form>
                <input type=button onclick="alert( parent.frametes t.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 ... !

                Comment

                • Martin Honnen

                  #9
                  Re: Accessing variables between frames



                  Frédéric Mayot wrote:
                  [color=blue]
                  > 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.[/color]

                  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


                  Comment

                  Working...