Accessing IFRAME content question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Brant

    #1

    Accessing IFRAME content question

    Hi all,

    I have a page with an IFRAME in it. From a script in the main ( parent )
    page I instruct the IFRAME to load a specific URL. The URL contains
    parameters that are processed by the server. The server then writes a result
    cookie into the content destined for the IFRAME.

    I am having issues accessing the cookie. If I use a debuger I can see the
    cookie via a quickwatch looking at window.frames['name].document.cooki e
    however when I run the code the same variable is empty. Does anyone have any
    ideas??

    Many thanks for your responses//

    Paul


  • Erwin Moller

    #2
    Re: Accessing IFRAME content question

    Paul Brant wrote:
    [color=blue]
    > Hi all,
    >
    > I have a page with an IFRAME in it. From a script in the main ( parent )
    > page I instruct the IFRAME to load a specific URL. The URL contains
    > parameters that are processed by the server. The server then writes a
    > result cookie into the content destined for the IFRAME.
    >
    > I am having issues accessing the cookie. If I use a debuger I can see the
    > cookie via a quickwatch looking at window.frames['name].document.cooki e
    > however when I run the code the same variable is empty. Does anyone have
    > any ideas??
    >
    > Many thanks for your responses//
    >
    > Paul[/color]

    Hi

    Is the URL in the IFRAME on the same domain as the mainpage?

    Regards,
    Erwin Moller

    Comment

    • Martin Honnen

      #3
      Re: Accessing IFRAME content question



      Paul Brant wrote:

      [color=blue]
      > I have a page with an IFRAME in it. From a script in the main ( parent )
      > page I instruct the IFRAME to load a specific URL. The URL contains
      > parameters that are processed by the server. The server then writes a result
      > cookie into the content destined for the IFRAME.
      >
      > I am having issues accessing the cookie. If I use a debuger I can see the
      > cookie via a quickwatch looking at window.frames['name].document.cooki e
      > however when I run the code the same variable is empty. Does anyone have any
      > ideas??[/color]

      The new page in the iframe needs to be loaded before document.cookie in
      that frame window can have the new cookies so you need to wait to have
      the page loaded.
      As you want to access the cookies from the containing window it is best
      you define a function there
      function processCookies (cookies) {
      ...
      }
      and then in the new frame loaded in the iframe you do
      if (parent && parent.processC ookies) {
      parent.processC ookies(document .cookie);
      }
      --

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

      Comment

      • Paul Brant

        #4
        Re: Accessing IFRAME content question


        "Erwin Moller"
        <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
        message news:420c8915$0 $28994$e4fe514c @news.xs4all.nl ...[color=blue]
        > Paul Brant wrote:
        >[color=green]
        > > Hi all,
        > >
        > > I have a page with an IFRAME in it. From a script in the main ([/color][/color]
        parent )[color=blue][color=green]
        > > page I instruct the IFRAME to load a specific URL. The URL contains
        > > parameters that are processed by the server. The server then writes a
        > > result cookie into the content destined for the IFRAME.
        > >
        > > I am having issues accessing the cookie. If I use a debuger I can see[/color][/color]
        the[color=blue][color=green]
        > > cookie via a quickwatch looking at window.frames['name].document.cooki e
        > > however when I run the code the same variable is empty. Does anyone have
        > > any ideas??
        > >
        > > Many thanks for your responses//
        > >
        > > Paul[/color]
        >
        > Hi
        >
        > Is the URL in the IFRAME on the same domain as the mainpage?
        >
        > Regards,
        > Erwin Moller[/color]

        Hey Erwin,

        While I do not specifiy a domain within the server code both pages load from
        the same host !

        Regards,

        Paul


        Comment

        • Paul Brant

          #5
          Re: Accessing IFRAME content question


          "Martin Honnen" <mahotrash@yaho o.de> wrote in message
          news:420c9ec1$0 $823$9b4e6d93@n ewsread2.arcor-online.net...[color=blue]
          >
          >
          > Paul Brant wrote:
          >
          >[color=green]
          > > I have a page with an IFRAME in it. From a script in the main ([/color][/color]
          parent )[color=blue][color=green]
          > > page I instruct the IFRAME to load a specific URL. The URL contains
          > > parameters that are processed by the server. The server then writes a[/color][/color]
          result[color=blue][color=green]
          > > cookie into the content destined for the IFRAME.
          > >
          > > I am having issues accessing the cookie. If I use a debuger I can see[/color][/color]
          the[color=blue][color=green]
          > > cookie via a quickwatch looking at window.frames['name].document.cooki e
          > > however when I run the code the same variable is empty. Does anyone have[/color][/color]
          any[color=blue][color=green]
          > > ideas??[/color]
          >
          > The new page in the iframe needs to be loaded before document.cookie in
          > that frame window can have the new cookies so you need to wait to have
          > the page loaded.
          > As you want to access the cookies from the containing window it is best
          > you define a function there
          > function processCookies (cookies) {
          > ...
          > }
          > and then in the new frame loaded in the iframe you do
          > if (parent && parent.processC ookies) {
          > parent.processC ookies(document .cookie);
          > }
          > --
          >
          > Martin Honnen
          > http://JavaScript.FAQTs.com/[/color]

          Hey Martin,

          many thanks for your post. I have progressed as a result of it. Given I own
          the source to the server I decided to move away from cookies. I am however
          ensuring that the document is loaded before proceeding. My iframe now calls
          setResult on the following:

          var processResult = new function() {
          var scratch;

          this.setResult = function(result ) {
          scratch = result;
          }

          this.getLastRes ult = function() {
          return scratch;
          }
          }


          I see scratch get set. When the parent (main) window then calls
          getLastResult i get undefined. If I debug I see the variable set corrently.
          Again.. if you have any thoughts I would be grateful.

          Paul


          Comment

          Working...