homepage Welcome to WebmasterWorld Guest from 54.198.25.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JScript loaded in head writes to document body
is it possible?
Stue

10+ Year Member



 
Msg#: 139 posted 7:57 am on Jun 20, 2002 (gmt 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.

 

PsychoTekk

10+ Year Member



 
Msg#: 139 posted 8:08 am on Jun 20, 2002 (gmt 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";

rewboss

10+ Year Member



 
Msg#: 139 posted 9:54 am on Jun 20, 2002 (gmt 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.

Andrew Revvo

10+ Year Member



 
Msg#: 139 posted 9:44 am on Jun 23, 2002 (gmt 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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved