Javascript question... 
Author Message
 Javascript question...

The position of an script in a page matters? If I put my scripts in <HEADER>
or <BODY>, what happens?

Fred



Fri, 13 Dec 2002 03:00:00 GMT  
 Javascript question...
I don't think it matters, but if it does I would be interested to learn why.
One thing for sure, is that if you are going to do operations that require
document.write() calls onto the page, you want to keep those in the body so
they print out visible in the browser.

Tom Lianza


Quote:
> The position of an script in a page matters? If I put my scripts in
<HEADER>
> or <BODY>, what happens?

> Fred



Fri, 13 Dec 2002 03:00:00 GMT  
 Javascript question...

Quote:
> The position of an script in a page matters? If I put my scripts in
<HEADER>
> or <BODY>, what happens?

The position does matter somewhat.

Originally, putting scripts inside the <head> (not <header> ;-) ) element
stopped the source code from being printed on the page if the browser didn't
understand the <script> tag.

Scripts are run as soon as they are downloaded, so if you rely on something
in the document to have already been created (like a <div> or an <input>)
then your code will have to appear after the element in the source code.

One way around this is to use the document.onload event handler, which will
run when everything on the page has loaded.

Peter

--
Peter J. Torr - Microsoft Windows Script Program Manager

Please do not e-mail me with questions - post them to this
newsgroup instead. Thankyou!



Sat, 14 Dec 2002 03:00:00 GMT  
 Javascript question...
    I read somewhere, that if you initialize variables in the head tag,
increases performance...
Quote:



> > The position of an script in a page matters? If I put my scripts in
> <HEADER>
> > or <BODY>, what happens?

> The position does matter somewhat.

> Originally, putting scripts inside the <head> (not <header> ;-) ) element
> stopped the source code from being printed on the page if the browser didn't
> understand the <script> tag.

> Scripts are run as soon as they are downloaded, so if you rely on something
> in the document to have already been created (like a <div> or an <input>)
> then your code will have to appear after the element in the source code.

> One way around this is to use the document.onload event handler, which will
> run when everything on the page has loaded.

> Peter

> --
> Peter J. Torr - Microsoft Windows Script Program Manager

> Please do not e-mail me with questions - post them to this
> newsgroup instead. Thankyou!



Sun, 15 Dec 2002 03:00:00 GMT  
 Javascript question...



Quote:


> > The position of an script in a page matters? If I put my scripts in
> <HEADER>
> > or <BODY>, what happens?

> The position does matter somewhat.

> Originally, putting scripts inside the <head> (not <header> ;-) ) element
> stopped the source code from being printed on the page if the browser
didn't
> understand the <script> tag.

> Scripts are run as soon as they are downloaded, so if you rely on
something
> in the document to have already been created (like a <div> or an <input>)
> then your code will have to appear after the element in the source code.

Slightly more than this, because, just because it's after it in the code,
doesn't mean that MSHTML has finished rendering it and it is in an
appropriate ReadyState to have anything done to it.

Jim.



Sun, 15 Dec 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. VBScript to Javascript question

2. Advanced JavaScript Question - IE - Permission denied Error

3. Javascript question?

4. CSS/JavaScript question (IE4 explicit)

5. Another Netscape Javascript question

6. BIG dhtml/javascript question?

7. I need to ask a Javascript question: NS Specific - CSS Sheets

8. vbscript javascript question

9. server side vbscript /javascript question

10. Javascript Question

11. VBScript to Javascript question

12. vbscript / javascript question

 

 
Powered by phpBB® Forum Software