PDA

View Full Version : Netscape 6: document.write in hidden layer rewrites entire page?


SpydermanLA
07-19-2002, 04:44 AM
I'm trying to dynamically set the content of a submenu. To start off with, the layer is hidden, and then set to 'visible' when the user rolls over the main navigation item. The script works great in IE, but (surprise, surprise) goes all to hell in Netscape. Here is the script I'm using:

<div id="entContent" style="position: absolute; visibility: visible; z-index: 60;">
<script language="JavaScript">
if(project!='hbo'){
document.write('<a href="portfolio.html?hbo&3"><div class="menuitems">HBO Films</div></a>')
} else {
document.write('<div class="menuitemsNull"><img src="../images/checkmark.gif" width="16" height="12" border="0"> HBO Films</div>')
}
}
</script>

Netscape apparently doesn't run the script until the layer is made visible (that's fine). It also runs the script every time the layer visibility is toggled (also fine). The problem is when it *does* run the script, it rewrites the entire page, so suddenly all you see is the content of that one line (not fine!).

Can anybody offer an explanation and (hopefully) a solution?

Thanks,

Spyderman

joh6nn
07-19-2002, 05:31 AM
when you use document.write, if the document has already closed (ie, has finished loading), then a new document is opened. no way around it.

as far as a solution, here's a possibility, though i haven't tested it.

<script language="JavaScript">
document.write('<div id="entContent" style="position: absolute; visibility: visible; z-index: 60;">'):
if(project!='hbo'){
document.write('<a href="portfolio.html?hbo&3"><div class="menuitems">HBO Films</div></a>')
} else {
document.write('<div class="menuitemsNull"><img src="../images/checkmark.gif" width="16" height="12" border="0"> HBO Films</div>')
}
document.write('</div>');
</script>

SpydermanLA
07-19-2002, 06:33 AM
Billiant, worked like a charm!

Cheers,

Spyderman