Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-15-2005, 07:03 AM
  #1
jasongr
Soldier (Level 11)
 
Join Date: Aug 2004
Posts: 105
iTrader: (0)
jasongr is on a distinguished road
document.write is deferred inside a table

Hello,

My application uses Web pages whose grid is defined by several tables. I noticed a funny behavior on IE and Firefox which is giving me pains.

Apparently, when the browser renders a <table> tag and before it reaches the </table> end tag, any document.write actions in Javascript get deferred execution till closure of table instead of occuring at runtime as they are parsed.

The following snippet demonstrates the problem:

Code:
<html> <body>
<script language="javascript">
document.write("before table");
alert("before table");
</script>

<table>

<script language="javascript">
document.write("in table PROBLEM");
alert("in table");
</script>

</table>

<script language="javascript">
document.write("after table");
alert("after table");
</script>

</body> </html>
When this snippet is run, the problematic document.write of "in table" gets deferred till after the table gets closed.
We use alert() calls here to stop rendering and clarify what happens when. You can see that the other document.write calls that are not in mid-table, are displayed properly.

In our real-world app this gives us a problem wherein we use document.write to render code that displays a Flash navigation menu component, but this Flash menu appears after the table tag is closed which is after rendering of entire page, so the Flash shows up to users very late after most of the page has loaded instead of showing up early as we require it.

Since we have to use the table as part of the layout grid of the site, please advise how to work around this issue.
Note that we render the Flash using document.write because we have a Javascript check if Flash exists or not, and if not, we render an alternative non-Flash menu.

Thanks!
jasongr is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-15-2005, 08:37 AM
  #2
RysChwith
Super Guru
 
Join Date: Jun 2004
Posts: 4,117
iTrader: (0)
RysChwith will become famous soon enough
The problem isn't in the JavaScript, but the HTML. If you walk through, you'll see that it's producing the equivalent of this:
Code:
<table>
in table PROBLEM
</table>
The text is in neither a <td> nor a <tr> tag, both of which are required in the table. Anything inside table tags, but outside the td and tr tags, will render after the table. So you'll need to modify the document.write to include those.

Rys
RysChwith is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-15-2005, 09:02 AM
  #3
jasongr
Soldier (Level 11)
 
Join Date: Aug 2004
Posts: 105
iTrader: (0)
jasongr is on a distinguished road
Hi RysChwith

I wanted to tell you that the scenario you described is not wrong
you can render elements that are not <tr> <td> right after the <table> tag and the browser will render them
Also, moving the document.write to after the <tr><td> has no effect and the problem still persists

Can you send me another answer that works?
jasongr is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-15-2005, 01:24 PM
  #4
RysChwith
Super Guru
 
Join Date: Jun 2004
Posts: 4,117
iTrader: (0)
RysChwith will become famous soon enough
Adding in the <tr> and <td> tags makes it work for me:
Code:
<html> <body>
<script language="javascript">
document.write("before table");
alert("before table");
</script>

<table border = "1"><tr><td>

<script language="javascript">
document.write("in table PROBLEM");
alert("in table");
</td></tr></script>

</table>

<script language="javascript">
document.write("after table");
alert("after table");
</script>

</body> </html>
Is the code you posted the actual code you're using? I'm assuming not. Post the actual code, and we can see what else is causing the problem.

Rys

Last edited by RysChwith : 09-15-2005 at 01:25 PM. Reason: Posted the wrong code
RysChwith is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:15 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.