Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

JScript loaded in head writes to document body

is it possible?



7:57 am on Jun 20, 2002 (gmt 0)

10+ Year Member

Ok im having this script that writes a specific DIV into the HTML. Normally when i wanted the script to write into the BODY of a document i would load it at the specific place in the BODY itself. But regarding the fact the i have to REPLACE an existing script by the new one, so that the new one is loaded instead of the old one, it would be toooooo much work to edit all existing HTML files of ALL existing projects (where the script is always loaded in the head). Thus i only have the chance to load the script in the head and somehow write the DIV layer to the BODY.

Shoot your ideas please.


8:08 am on Jun 20, 2002 (gmt 0)

10+ Year Member

<script language="JavaScript" src="data.js" type="text/javascript"></script>
<div id="jsTarget"></div>


document.all.jsTarget.innerHTML = "whatever goes here";


9:54 am on Jun 20, 2002 (gmt 0)

10+ Year Member

PsychoTekk's solution will generate a runtime error in Netscape 4.

I'd take the general idea of using an external .js file, but I would put the document.write() statements in a function:

function writeDiv(){

Then, in the HTML file itself, you need to write:


However, this unreliable to say the least. A far more workable solution would be to use a client-side script.

Andrew Revvo

9:44 am on Jun 23, 2002 (gmt 0)

10+ Year Member

Stue: It is posible, but your head code must know that your web page is fully loaded.
I use flags and place them to the BODY code like:

<script language="JavaScript"> IsLoaded = 1;</script>

We used this technique on the our web site for a main menu layer changing. <snip>

[edited by: papabaer at 12:18 pm (utc) on June 23, 2002]


Featured Threads

Hot Threads This Week

Hot Threads This Month