content added to DIV at runtime: timing

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

    #1

    content added to DIV at runtime: timing

    When content is transferred from a hidden IFRAME (which has fetched data
    from a database) to a DIV in the main document, how can a script determine
    that the DIV has been completely populated before it acts upon the data?

    if (myIFRAME.docum ent.readyState= ='complete')
    myDIV.insertAdj acentHTML("afte rBegin",
    myIFRAME.window .document.getEl ementById('data ') )
    // ...
    // convert text in myDIV to uppercase
    // code here may execute before action in line above completes, right?


    Thanks
    Timo



  • Martin Honnen

    #2
    Re: content added to DIV at runtime: timing



    Timo wrote:
    [color=blue]
    > When content is transferred from a hidden IFRAME (which has fetched data
    > from a database) to a DIV in the main document, how can a script determine
    > that the DIV has been completely populated before it acts upon the data?
    >
    > if (myIFRAME.docum ent.readyState= ='complete')
    > myDIV.insertAdj acentHTML("afte rBegin",
    > myIFRAME.window .document.getEl ementById('data ') )
    > // ...
    > // convert text in myDIV to uppercase
    > // code here may execute before action in line above completes, right?[/color]

    I don't see why it would makes sense to insert a HTML element with
    insertAdjacentH TML so I guess if the element with id data is a form
    control you want

    myDIV.insertAdj acentHTML("afte rBegin",
    myIFRAME.window .document.getEl ementById('data ').value)

    or if it is a HTML container element you want

    myDIV.insertAdj acentHTML("afte rBegin",
    myIFRAME.window .document.getEl ementById('data ').innerHTML);

    but I don't see a timing problem, document manipulation happens
    synchronously as long as you do not insert elements which load external
    resources.

    However you whole scripting seems to be geared towards the IE object
    model as insertAdjacentH TML is not part of the W3C DOM so consider to
    change to the W3C DOM if you want to build a page working with as many
    of the modern browsers as possible.

    --

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

    Comment

    • Timo

      #3
      Re: content added to DIV at runtime: timing

      Martin,
      Thanks for taking time to reply. I'll share more detail about the scenario.
      zzzzz....

      I'm building a treeview-like navigation interface, where the childnodes are
      <A> elements.Each parent node in the tree has an empty DIV to hold its
      childen. The tree is only two levels deep. The first major challenge is that
      dataset that populates the treeview is so large that it cannot be downloaded
      all at once for performance/latency reasons; so data are retrieved in
      pieces, only as needed, upon node-expand. Only the first level is built upon
      page load.

      The data are fetched from the database via a hidden IFRAME conduit (instead
      of XMLHTTP) and then, when the IFRAME's document has loaded (setTimeout,
      readyState==com plete) the contents of a DIV on the hidden IFRAME are moved,
      as one block of html in one fell swoop into an empty DIV in the main page.
      Each parent node has such a DIV for its child nodes. When the node is
      collapsed the DIV is made invisible.

      A second perhaps insurmountable challenge is that the customer wants the
      treeview to be stateful without using postbacks. My choices, as I see them,
      are to write back to the database via another hidden IFRAME or via XMLHTTP,
      or to use cookies. Any other way to maintain state without using postback?
      Remoting maybe. But for me, remoting is like The Paths of the Dead in LOTR.
      I'll take that route last.

      At the moment, I'm trying the cookie approach. The customer wants the
      treeview to look exactly as it was -- all previously opened nodes still open
      and populated-- when the user returns to the page after visiting another.
      So, upon node-expand, I'm storing each DIV's worth of childnodes retrieved
      from the database in a separate session cookie; each populated DIV has its
      own cookie which contains the DIV's innerHTML. When the treeview page is
      loaded, I read those cookies and repopulate each childnode DIVs in my
      OpenNodesList (also stored as a cookie).

      Problem: my code works in the IE debugger but often not at runtime.
      Sometimes the DIVS do not get repopulated. So I'm assuming there's a timing
      issue between reading the cookie and writing to the DIV. Sometimes the
      cookie might contain 20K. I'm in a tight loop reading cookies and with each
      iteration inserting a block of HTML into the target DIV:

      PSEUDOCODE:

      for each node in OpenNodesList
      // myData contains a series of <A> elements
      // DIV is empty before the insert
      myData = GetCookie(node)
      getDIV(node).in sertAdjacentHTM L = myData

      I'll find the non-proprietary way to insert the HTML into the target DIV
      after I've proved (or disproved) the viability of the concept in IE. But is
      the above loop actually feasible? GetCookie would also have to be
      synchronous, right?
      Timo

      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:40ebd2f3$1 @olaf.komtel.ne t...
      :
      :
      : : I don't see why it would makes sense to insert a HTML element with
      : insertAdjacentH TML so I guess if the element with id data is a form
      : control you want
      :
      : myDIV.insertAdj acentHTML("afte rBegin",
      : myIFRAME.window .document.getEl ementById('data ').value)
      :
      : or if it is a HTML container element you want
      :
      : myDIV.insertAdj acentHTML("afte rBegin",
      : myIFRAME.window .document.getEl ementById('data ').innerHTML);
      :
      : but I don't see a timing problem, document manipulation happens
      : synchronously as long as you do not insert elements which load external
      : resources.
      :
      : However you whole scripting seems to be geared towards the IE object
      : model as insertAdjacentH TML is not part of the W3C DOM so consider to
      : change to the W3C DOM if you want to build a page working with as many
      : of the modern browsers as possible.
      :
      : --
      :
      : Martin Honnen
      : http://JavaScript.FAQTs.com/
      :


      Comment

      Working...