Welcome to WebmasterWorld Guest from 54.145.176.252

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)

New User

10+ Year Member

joined:Apr 30, 2002
posts:13
votes: 0


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 June 20, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Feb 24, 2002
posts:289
votes: 0


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

data.js:

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

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

Preferred Member

10+ Year Member

joined:June 7, 2002
posts:475
votes: 0


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(){
document.write('.......');
}

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

<script>
writeDiv();
</script>

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

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

New User

10+ Year Member

joined:June 23, 2002
posts:2
votes: 0


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:

...
SOME HTML
...
<script language="JavaScript"> IsLoaded = 1;</script>
...
SOME HTML
...

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]