Javascript Display out of order

Discussion in 'Javascript' started by bgold, Jul 14, 2008.

  1. bgold

    bgold Guest

    Hey, I've had this problem for a while and never fixed it, cause it's
    not catastrophic, but it's really annoying and I'm hoping someone can
    help me.

    I have an html file that has mixed html tags and javascript functions
    which call document.write and do some XML stuff. Now, the weird thing
    is, it always runs perfectly in IE, but in FF it runs perfectly some
    of the time, and doesn't some of the time. When I reload the page like
    20 times in a row, and about 3/4 of the time it displays perfectly,
    but the rest of the time a javascript function seems to be called out
    of order. For example, instead of being called somewhere in the middle
    of the page and displaying text there, it gets called after the entire
    rest of the page has been displayed, and thus the output of the
    function appears at the bottom of the page. What could possibly be
    going on that causes this strange error only some of the time in FF?

    I haven't copied my code here, cause there's a lot of it, but if you
    want to look at it then I could try to create a test case that has the
    same problem and copy that here (I probably could do that pretty
    quickly).

    Thanks.

    Benji
    bgold, Jul 14, 2008
    #1
    1. Advertising

  2. bgold

    Tom Cole Guest

    On Jul 14, 6:40 pm, bgold <> wrote:
    > Hey, I've had this problem for a while and never fixed it, cause it's
    > not catastrophic, but it's really annoying and I'm hoping someone can
    > help me.
    >
    > I have an html file that has mixed html tags and javascript functions
    > which call document.write and do some XML stuff. Now, the weird thing
    > is, it always runs perfectly in IE, but in FF it runs perfectly some
    > of the time, and doesn't some of the time. When I reload the page like
    > 20 times in a row, and about 3/4 of the time it displays perfectly,
    > but the rest of the time a javascript function seems to be called out
    > of order. For example, instead of being called somewhere in the middle
    > of the page and displaying text there, it gets called after the entire
    > rest of the page has been displayed, and thus the output of the
    > function appears at the bottom of the page. What could possibly be
    > going on that causes this strange error only some of the time in FF?
    >
    > I haven't copied my code here, cause there's a lot of it, but if you
    > want to look at it then I could try to create a test case that has the
    > same problem and copy that here (I probably could do that pretty
    > quickly).
    >
    > Thanks.
    >
    > Benji


    You should refrain from using document.write in the middle of your
    document. Rather, leave place holders for your output (i.e. div or
    spans) and then call your javascript functions from document.onload(),
    updating the contents (innerHTML) of your placeholders.
    Tom Cole, Jul 14, 2008
    #2
    1. Advertising

  3. bgold

    bgold Guest

    On Jul 14, 6:57 pm, Tom Cole <> wrote:
    > On Jul 14, 6:40 pm, bgold <> wrote:
    >
    >
    >
    > > Hey, I've had this problem for a while and never fixed it, cause it's
    > > not catastrophic, but it's really annoying and I'm hoping someone can
    > > help me.

    >
    > > I have an html file that has mixed html tags and javascript functions
    > > which call document.write and do some XML stuff. Now, the weird thing
    > > is, it always runs perfectly in IE, but in FF it runs perfectly some
    > > of the time, and doesn't some of the time. When I reload the page like
    > > 20 times in a row, and about 3/4 of the time it displays perfectly,
    > > but the rest of the time a javascript function seems to be called out
    > > of order. For example, instead of being called somewhere in the middle
    > > of the page and displaying text there, it gets called after the entire
    > > rest of the page has been displayed, and thus the output of the
    > > function appears at the bottom of the page. What could possibly be
    > > going on that causes this strange error only some of the time in FF?

    >
    > > I haven't copied my code here, cause there's a lot of it, but if you
    > > want to look at it then I could try to create a test case that has the
    > > same problem and copy that here (I probably could do that pretty
    > > quickly).

    >
    > > Thanks.

    >
    > > Benji

    >
    > You should refrain from using document.write in the middle of your
    > document. Rather, leave place holders for your output (i.e. div or
    > spans) and then call your javascript functions from document.onload(),
    > updating the contents (innerHTML) of your placeholders.


    Thanks for your reply. I'd like some more information, if you don't
    mind.

    What is it about document.write that is problematic? Does it somehow
    work asynchronously with the rest of the display? I've always assumed
    that it would be written to the document in the order it's called in
    the html document.

    Also, I have a variable amount of html tags and text to output. How
    would I implement your solution in this case? Could I use html to
    leave a main placeholder like <div id="main">...</div> and then use
    the document.onload() function to write a variable number of
    <span>...</span> etc. tags and text into the innerHTML contents of the
    main placeholder?
    bgold, Jul 15, 2008
    #3
  4. In comp.lang.javascript message <34bba1dc-a6e3-4cf7-a10c-92122666a00c@z6
    6g2000hsc.googlegroups.com>, Mon, 14 Jul 2008 15:57:54, Tom Cole
    <> posted:
    >
    >You should refrain from using document.write in the middle of your
    >document. Rather, leave place holders for your output (i.e. div or
    >spans) and then call your javascript functions from document.onload(),
    >updating the contents (innerHTML) of your placeholders.
    >


    Can you post a short sample page which shows that not working? I have
    no perceived problem with it myself, and it's common on my site.
    There's at least one case where the code including the write takes
    longer to execute than the rest of the page would have taken to load.

    It's a good idea to read the newsgroup c.l.j and its dead FAQ. See below.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Jul 15, 2008
    #4
  5. Tom Cole wrote:
    > On Jul 14, 6:40 pm, bgold <> wrote:
    >> I have an html file that has mixed html tags and javascript functions
    >> which call document.write and do some XML stuff. Now, the weird thing
    >> is, it always runs perfectly in IE, but in FF it runs perfectly some
    >> of the time, and doesn't some of the time. When I reload the page like
    >> 20 times in a row, and about 3/4 of the time it displays perfectly,
    >> but the rest of the time a javascript function seems to be called out
    >> of order. [...]
    >> [...]

    >
    > You should refrain from using document.write in the middle of your
    > document. Rather, leave place holders for your output (i.e. div or
    > spans) and then call your javascript functions from document.onload(),
    > updating the contents (innerHTML) of your placeholders.


    Utter nonsense. document.write() is part of a Web standard; `innerHTML'
    is not and it has a number of issues as well, not to mention that it
    introduces another problem with accessing elements in different DOMs.

    The OP should better analyze the document.write() calls and make sure they
    are performed in the right place (i.e. ensure Valid markup first).


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Jul 15, 2008
    #5
  6. bgold wrote:
    > I have an html file that has mixed html tags and javascript functions
    > which call document.write and do some XML stuff. Now, the weird thing is,
    > it always runs perfectly in IE, but in FF it runs perfectly some of the
    > time, and doesn't some of the time. When I reload the page like 20 times
    > in a row, and about 3/4 of the time it displays perfectly, but the rest
    > of the time a javascript function seems to be called out of order. [...]
    >
    > [...] if you want to look at it then I could try to create a test case
    > that has the same problem and copy that here (I probably could do that
    > pretty quickly).


    Please do.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Jul 15, 2008
    #6
  7. bgold

    Jorge Guest

    On Jul 15, 12:40 am, bgold <> wrote:
    > Hey, I've had this problem for a while and never fixed it, cause it's
    > not catastrophic, but it's really annoying and I'm hoping someone can
    > help me.
    >
    > I have an html file that has mixed html tags and javascript functions
    > which call document.write and do some XML stuff. Now, the weird thing
    > is, it always runs perfectly in IE, but in FF it runs perfectly some
    > of the time, and doesn't some of the time. When I reload the page like
    > 20 times in a row, and about 3/4 of the time it displays perfectly,
    > but the rest of the time a javascript function seems to be called out
    > of order. For example, instead of being called somewhere in the middle
    > of the page and displaying text there, it gets called after the entire
    > rest of the page has been displayed, and thus the output of the
    > function appears at the bottom of the page. What could possibly be
    > going on that causes this strange error only some of the time in FF?
    >


    I have had a similar problem with this page : http://tinyurl.com/5sx3jr
    Hit reload repeatedly and sooner or later some XHRs will get misplaced
    at the botton (only happens in FF2).
    I can't figure out why.

    --Jorge.
    Jorge, Jul 16, 2008
    #7
    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. Homa
    Replies:
    2
    Views:
    351
  2. Soren Kuula
    Replies:
    2
    Views:
    482
    Soren Kuula
    Feb 1, 2004
  3. cspoh
    Replies:
    0
    Views:
    234
    cspoh
    Jul 31, 2003
  4. Stephan Kämper
    Replies:
    2
    Views:
    227
    Stephan Kämper
    Jan 18, 2004
  5. Smriti Dev
    Replies:
    1
    Views:
    80
    Grant Wagner
    Dec 3, 2003
Loading...

Share This Page