Javascript Display out of order

B

bgold

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
 
T

Tom Cole

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.
 
B

bgold

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?
 
D

Dr J R Stockton

In comp.lang.javascript message <34bba1dc-a6e3-4cf7-a10c-92122666a00c@z6
6g2000hsc.googlegroups.com>, Mon, 14 Jul 2008 15:57:54, Tom Cole
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.
 
T

Thomas 'PointedEars' Lahn

Tom said:
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
 
T

Thomas 'PointedEars' Lahn

bgold said:
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
 
J

Jorge

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top