[thelist] [JS]: document.write vs innerHTML

J.J.SOLARI jjsolari at pobox.com
Sun Oct 15 14:41:31 CDT 2000


Hello all,

I came across a weird behaviour of IE5 Mac edition regarding some javascript
code ; here is a test page demonstrating the problem:

==========
<html>
<head>
<title>Test</title>
<style type="text/css"><!-- #palette {position:absolute;} 
--></style>
</head>
<body onload="pWrite()">
<div id="palette">
</div>
<script type="text/javascript"><!-- 
var ns=(document.layers)?true:false,ie=(document.all)?true:false ;

<!-- Array of 24 values -->
var p = new Array("ffffff","ccffff","99ffff","66ffff","33ffff",
"00ffff","ffccff","ccccff","99ccff","66ccff","33ccff","00ccff",
"ff99ff","cc99ff","9999ff","6699ff","3399ff","0099ff","ff66ff",
"cc66ff","9966ff","6666ff","3366ff","0066ff");

function pWrite() {

tmp = '<table border=0 cellspacing=9 cellpadding=0><tr>' ;

for (i=0;i< p.length;i++)
{
tmp += '<td bgcolor=\"#'+p[i]+'\">'+i+'<\/td>' ;
if ((i+1)%12==0&&(i+1)<p.length){tmp += '<\/tr><tr>' ;}
}
tmp += '<\/tr><\/table>' ;
if (ns)
{
document.palette.document.write(tmp) ;
document.palette.document.close() ;
}
if (ie)
{
document.all.palette.innerHTML = tmp ;
}
}
// -->
</script>
</body>
</html>
=========

It should build two rows of twelve colored cells.
Netscape 4.08 does what is expected, whereas IE5 just displays the last row,
and I'm told that it works fine on Win versions.

Am I missing the obvious?

tia,

JJS.

P.S.: This page is online at: <http://www.yoyodesign.org/tmp/cb.html>
-- 
/* public key id: 9eb99ddb <http://www.keyserver.net/> */
/* homepage <http://www.yoyodesign.org/> */
-- 
/* public key id: 9eb99ddb <http://www.keyserver.net/> */
/* homepage <http://www.yoyodesign.org/> */






More information about the thelist mailing list