Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript Display out of order

Reply
Thread Tools

Javascript Display out of order

 
 
bgold
Guest
Posts: n/a
 
      07-14-2008
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
 
Reply With Quote
 
 
 
 
Tom Cole
Guest
Posts: n/a
 
      07-14-2008
On Jul 14, 6:40*pm, bgold <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
 
bgold
Guest
Posts: n/a
 
      07-14-2008
On Jul 14, 6:57*pm, Tom Cole <(E-Mail Removed)> wrote:
> On Jul 14, 6:40*pm, bgold <(E-Mail Removed)> 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?
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      07-15-2008
In comp.lang.javascript message <34bba1dc-a6e3-4cf7-a10c-92122666a00c@z6
6g2000hsc.googlegroups.com>, Mon, 14 Jul 2008 15:57:54, Tom Cole
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      07-15-2008
Tom Cole wrote:
> On Jul 14, 6:40 pm, bgold <(E-Mail Removed)> 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
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      07-15-2008
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
 
Reply With Quote
 
Jorge
Guest
Posts: n/a
 
      07-16-2008
On Jul 15, 12:40*am, bgold <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kämper Ruby 2 01-18-2004 02:07 PM
Javascript Drop Down Menu - problem with order & display Smriti Dev Javascript 1 12-03-2003 08:42 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM



Advertisments