A Challenge: Call parent Javascript function from inside an iframe?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Ianson

    A Challenge: Call parent Javascript function from inside an iframe?

    Hi geniuses (or is that genii, or genies)

    The challenge is as above really. I have a page with an iframe in it, and
    need to call a JS function in the *parent* page, *from* inside the iframe.

    (It's for Google Maps, but I won't bore you with the complexities of that,
    as it doesn't affect the question).

    Mochas kudos to anyone able to solve this widdle.

    Ta.


  • Jonathan N. Little

    #2
    Re: A Challenge: Call parent Javascript function from inside an iframe?

    Chris Ianson wrote:[color=blue]
    > Hi geniuses (or is that genii, or genies)
    >
    > The challenge is as above really. I have a page with an iframe in it, and
    > need to call a JS function in the *parent* page, *from* inside the iframe.
    >
    > (It's for Google Maps, but I won't bore you with the complexities of that,
    > as it doesn't affect the question).
    >
    > Mochas kudos to anyone able to solve this widdle.[/color]

    Still flogging the iframe 'dead horse' I see.

    parent.yourfunc tion();


    Don't try patenting it though...


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO

    Comment

    • Chris Ianson

      #3
      Re: A Challenge: Call parent Javascript function from inside an iframe?

      "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
      news:443336ae$0 $3697$cb0e7fc6@ news.centralva. net...
      [color=blue]
      > Still flogging the iframe 'dead horse' I see.[/color]

      :( By 'dead horse' I assume you mean 'now working perfectly in all
      browsers'.
      [color=blue]
      > parent.yourfunc tion();[/color]

      Sadly this doesn't seem to work for Google Maps API. Are there any other
      methods to call JS from the parent frame?
      [color=blue]
      > Don't try patenting it though...[/color]

      Too right, I have enough of them already...

      TIA :)


      Comment

      • Jonathan N. Little

        #4
        Re: A Challenge: Call parent Javascript function from inside an iframe?

        Chris Ianson wrote:[color=blue]
        > "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
        > news:443336ae$0 $3697$cb0e7fc6@ news.centralva. net...
        >[color=green]
        >> Still flogging the iframe 'dead horse' I see.[/color]
        >
        > :( By 'dead horse' I assume you mean 'now working perfectly in all
        > browsers'.
        >[color=green]
        >> parent.yourfunc tion();[/color]
        >
        > Sadly this doesn't seem to work for Google Maps API. Are there any other
        > methods to call JS from the parent frame?[/color]



        Google Maps API Documentation
        --
        Take care,

        Jonathan
        -------------------
        LITTLE WORKS STUDIO

        Comment

        • Chris Ianson

          #5
          Re: A Challenge: Call parent Javascript function from inside an iframe?

          "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
          news:4433f73b$0 $3681$cb0e7fc6@ news.centralva. net...
          [color=blue]
          > http://www.google.com/apis/maps/documentation/
          > Google Maps API Documentation[/color]

          Yes, I am far too familiar with that URL having used it for the past few
          weeks.

          The question I have asked is not covered therein.

          If anyone is able to provide an answer that would be great.

          TIA.


          Comment

          • Jonathan N. Little

            #6
            Re: A Challenge: Call parent Javascript function from inside an iframe?

            Chris Ianson wrote:[color=blue]
            > "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
            > news:4433f73b$0 $3681$cb0e7fc6@ news.centralva. net...
            >[color=green]
            >> http://www.google.com/apis/maps/documentation/
            >> Google Maps API Documentation[/color]
            >
            > Yes, I am far too familiar with that URL having used it for the past few
            > weeks.
            >
            > The question I have asked is not covered therein.
            >
            > If anyone is able to provide an answer that would be great.[/color]

            Sorry this IS how you reference a function in the parent frame. If it
            does not work for you then you must be and error of how you are using
            the function. Without URL only speculation.

            --
            Take care,

            Jonathan
            -------------------
            LITTLE WORKS STUDIO

            Comment

            • Chris Ianson

              #7
              Re: A Challenge: Call parent Javascript function from inside an iframe?

              "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
              news:443406c6$0 $3703$cb0e7fc6@ news.centralva. net...
              [color=blue]
              > Sorry this IS how you reference a function in the parent frame. If it does
              > not work for you then you must be and error of how you are using the
              > function. Without URL only speculation.[/color]

              Are you familiar with Google Maps API Jonathan? I have been working with an
              expert in the field and neither of us can get it to work. If you are more
              of an expert with the API then we can talk further.


              Comment

              • Jonathan N. Little

                #8
                Re: A Challenge: Call parent Javascript function from inside an iframe?

                Chris Ianson wrote:[color=blue]
                > "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
                > news:443406c6$0 $3703$cb0e7fc6@ news.centralva. net...
                >[color=green]
                >> Sorry this IS how you reference a function in the parent frame. If it does
                >> not work for you then you must be and error of how you are using the
                >> function. Without URL only speculation.[/color]
                >
                > Are you familiar with Google Maps API Jonathan? I have been working with an
                > expert in the field and neither of us can get it to work. If you are more
                > of an expert with the API then we can talk further.
                >
                >[/color]
                I am familiar with web design, and JavaScript. That is how you reference
                a JavaScript function in a non-named parent frame.

                No Details
                No URL
                No Code.

                What do you want?

                --
                Take care,

                Jonathan
                -------------------
                LITTLE WORKS STUDIO

                Comment

                • Marcello

                  #9
                  Re: A Challenge: Call parent Javascript function from inside an iframe?

                  Hi guys,

                  sorry to break the 'this works - no this doesn't work' quarrel, but
                  Chris, have you tried something different?

                  I've never used Google Maps API, so I don't know if you have access to
                  code on the parent window. If you do, put a function over there that
                  access the Google Maps one, and your function in the IFrame then access
                  your function in the parent frame.

                  If that still doesn't work, try putting and invisible FRAME (not
                  IFrame) in the parent window to do the same 'proxy function' approach.
                  I had to do it once, in another problem. For some reason it was not
                  working from parent to child <-> child to parent frames, but taking
                  this proxy function approach solved the problem.

                  Also, are you passing 'objects' or functions as parameters in this
                  call?

                  Thanks,
                  Marcello

                  Comment

                  • Chris Ianson

                    #10
                    Re: A Challenge: Call parent Javascript function from inside an iframe?

                    "Jonathan N. Little" <lws4art@centra lva.net> wrote in message
                    news:4434637b$0 $3694$cb0e7fc6@ news.centralva. net...
                    [color=blue][color=green]
                    >> Are you familiar with Google Maps API Jonathan? I have been working with
                    >> an expert in the field and neither of us can get it to work. If you are
                    >> more of an expert with the API then we can talk further.[/color][/color]

                    Google Maps is a bit of an entity unto itself.
                    [color=blue]
                    > I am familiar with web design, and JavaScript. That is how you reference a
                    > JavaScript function in a non-named parent frame.[/color]

                    ....only it doesn't work with Google so...
                    [color=blue]
                    > What do you want?[/color]

                    ....my question was a simple one which I will repeat for you as you are
                    asking what I want:
                    "Are there any other
                    methods to call JS from the parent frame?"


                    Comment

                    • Chris Ianson

                      #11
                      Re: A Challenge: Call parent Javascript function from inside an iframe?

                      "Marcello" <marcello.antol ino@gmail.com> wrote in message
                      news:1144327408 .574209.5060@v4 6g2000cwv.googl egroups.com...
                      [color=blue]
                      > I've never used Google Maps API, so I don't know if you have access to
                      > code on the parent window. If you do, put a function over there that
                      > access the Google Maps one, and your function in the IFrame then access
                      > your function in the parent frame.[/color]

                      Yep we actually just tried something similar.

                      The parent page now declares a map function called "walk()".

                      The child page (iframe) should no longer make its own changes to the iframe
                      contents. When it wants to jump, it should make calls like
                      "javascript:par ent.walk(3)"

                      [if you're unfamiliar with what is going on in the iframe from a previous
                      discussion here, there's an example at


                      The parent code will then update the map *and* update the iframe contents.
                      Simple.

                      Trouble is, it means that navigating in the iframe then relies on JS, which
                      rules out around 10% of people. Their loss sure, but still not ideal. We
                      are looking to keep the navigation as HTML.
                      [color=blue]
                      > If that still doesn't work, try putting and invisible FRAME (not
                      > IFrame) in the parent window to do the same 'proxy function' approach.
                      > I had to do it once, in another problem. For some reason it was not
                      > working from parent to child <-> child to parent frames, but taking
                      > this proxy function approach solved the problem.[/color]

                      Have passed this on to the other designer and will keep fingers crossed!
                      [color=blue]
                      > Also, are you passing 'objects' or functions as parameters in this
                      > call?[/color]

                      Only as above really.

                      Thanks for your constructive reply Marcello. You seem to have understood
                      what we are after. Cheers.


                      Comment

                      • Jonathan N. Little

                        #12
                        Re: A Challenge: Call parent Javascript function from inside an iframe?

                        Marcello wrote:[color=blue]
                        > Hi guys,
                        >
                        > sorry to break the 'this works - no this doesn't work' quarrel, but
                        > Chris, have you tried something different?
                        >
                        > I've never used Google Maps API, so I don't know if you have access to
                        > code on the parent window. If you do, put a function over there that
                        > access the Google Maps one, and your function in the IFrame then access
                        > your function in the parent frame.
                        >
                        > If that still doesn't work, try putting and invisible FRAME (not
                        > IFrame) in the parent window to do the same 'proxy function' approach.
                        > I had to do it once, in another problem. For some reason it was not
                        > working from parent to child <-> child to parent frames, but taking
                        > this proxy function approach solved the problem.
                        >
                        > Also, are you passing 'objects' or functions as parameters in this
                        > call?
                        >[/color]

                        Since here has not event identified what Google Maps API function he is
                        trying to call this is all speculation! Google Maps API seems to be
                        standard JavaScript. The API seems very straight forward where you
                        reference the map element on your document and they have built the API
                        as OOP where your call various object methods to control the map. What
                        is unclear is:

                        1) What an IFRAME
                        2) What function
                        3) Is the function is code or Googles
                        4) Is his code in the parent frame or the iframe
                        5) Some code...URL something.

                        Lastly I stand by my statement, that is how you reference an anonymous
                        parent frame function. Would be willing to assist if more info was
                        supplied. Really.


                        --
                        Take care,

                        Jonathan
                        -------------------
                        LITTLE WORKS STUDIO

                        Comment

                        • Jonathan N. Little

                          #13
                          Re: A Challenge: Call parent Javascript function from inside an iframe?

                          Chris Ianson wrote:[color=blue]
                          > "Marcello" <marcello.antol ino@gmail.com> wrote in message
                          > news:1144327408 .574209.5060@v4 6g2000cwv.googl egroups.com...
                          >[color=green]
                          >> I've never used Google Maps API, so I don't know if you have access to
                          >> code on the parent window. If you do, put a function over there that
                          >> access the Google Maps one, and your function in the IFrame then access
                          >> your function in the parent frame.[/color]
                          >
                          > Yep we actually just tried something similar.
                          >
                          > The parent page now declares a map function called "walk()".[/color]

                          walk() is this your function? There is not method 'walk' described in
                          any of the Google Maps object constructor that I can find.
                          [color=blue]
                          >
                          > The child page (iframe) should no longer make its own changes to the iframe
                          > contents. When it wants to jump, it should make calls like
                          > "javascript:par ent.walk(3)"[/color]

                          are you calling the function via <a href="javascrip t:parent.walk(3 )...
                          if you this may be your problem. do not put "javascript:som efunction()"
                          in a href attribute, put it on the event handler, i.e.,
                          onclick="somefu nction()"[color=blue]
                          >
                          > [if you're unfamiliar with what is going on in the iframe from a previous
                          > discussion here, there's an example at
                          > http://www.cjse.pwp.blueyonder.co.uk/misc/A1master.htm][/color]

                          Do not see reference to walk() in above code? what is the walk
                          function's code?

                          <snip>

                          --
                          Take care,

                          Jonathan
                          -------------------
                          LITTLE WORKS STUDIO

                          Comment

                          • Marcello

                            #14
                            Re: A Challenge: Call parent Javascript function from inside an iframe?

                            Thanks Chris;

                            if I understood correctly, basically one other problem that you have is
                            having to process many stuff at the same time, in JavaScript, then
                            browser's response to the user gets cranky. Is that ight?

                            Comment

                            • Chris Ianson

                              #15
                              Re: A Challenge: Call parent Javascript function from inside an iframe?

                              "Marcello" <marcello.antol ino@gmail.com> wrote in message
                              news:1144343325 .371143.129090@ t31g2000cwb.goo glegroups.com.. .[color=blue]
                              > Thanks Chris;
                              >
                              > if I understood correctly, basically one other problem that you have is
                              > having to process many stuff at the same time, in JavaScript, then
                              > browser's response to the user gets cranky. Is that ight?[/color]

                              No, that's not really a problem. Phew! :)

                              Here is a summary of where we're a bit stuck (sorry I have no live code at
                              the moment):

                              Basically I have one web page now with a Google Map in it, and below the
                              map is an inline frame containing a panoramic image. I have inserted a
                              series of markers onto the map. When a marker is clicked, a relevant photo
                              loads in the iframe.

                              However, it is also possible to change the image *from within* the iframe
                              itself, as per the example URL. E.g. clicking Go To End moves you to the
                              end of the image. Clicking Walk Right moves you to the next image.

                              ***The challenge is getting the map to respond when this happens.***

                              E.g. clicking on a park in the map would bring up a photo of the park
                              in the iframe (that bit works). Conversely selecting the park image from a
                              text hyperlink *in* the iframe should scroll the map to centre and highlight
                              the related marker on the park in the map (that bit eludes us).

                              Hope that clarifies. I can't be any clearer until we have a URL demo.


                              Comment

                              Working...