[thelist] document.write() in head section

Ben Henick persist1 at io.com
Tue Feb 19 21:35:01 CST 2002


On Tue, 19 Feb 2002, Syed Zeeshan Haider wrote:

> Hello Everybody,
> Is there something wrong about writing document.werite() in the head
> section of a web page? I have created a web page with all JavaScript in

Canonically (though not in all applications) most document methods are
meant to be applied to the body only.  For stylesheets, scripts, and
titles you can manipulate document.stylesheets, document.scripts, and
document.title (the first two arrays, the third a property)
respectively... in compilant useragents.

That said, Netscape and IE both allow document.write to be used for the
writing of tags that are structural children of HEAD and will download
files accordingly.  Opera does not.

> head section. When I click a button, JavaScript is supposed to write
> some message on the page. But sometimes it works and some time it
> doesn't. When it does not work, I have to close the web page and then
> open it again. What the problem is? I have inserted document.write()
> into head section. Is this creating problem?

I'm going to make a WAG in regards to your implementation, but...

if you want to manipulate page contents after the page loads, you need to
do one of the following:

1.  Change the innerHTML or innerText property of the part of the document
    you're manipulating (keeping in mind that innerText is not part of the
    Mozilla DOM implementation, and neither approach is standards-
    compliant)
2.  Remove the textNode(s) you're seeking to change, then creating and
    appending the new one(s)

I'm intending to write an article that serves as an overview of w3c DOM
properties and methods.  I may publish it on my own site, I may publish it
on evolt, I may publish it on ALA.

Don't know yet.  But it's near the front of my queue.


--
Ben Henick
Web Author At-Large              Managing Editor
http://www.io.com/persist1/      http://www.digital-web.com/
persist1 at io.com                  bmh at digital-web.com
--
"Are you pondering what I'm pondering, Pinky?"
"I think so, Brain, but... (snort) no, no, it's too stupid."
"We will disguise ourselves as a cow."
"Oh!" (giggles) "That was it exactly!"




More information about the thelist mailing list