html - How does the location of a script tag in a page affect a JavaScript function that is defined in it? -


I've read that your code will be & lt; Head & gt; should be defined in the tag, but how it is & lt; Script & gt; The location of ( gt; , & lt; body & gt; , or any other tag) affects a javascript function .

Specifically, how does it affect the scope of the function and where can you call it?

sounds to add people to the head Is appropriate, but as the others have said that there are several reasons why it is not recommended or not practical - mainly the speed and the way HTML pages are generated dynamically.

This is what:

SCRIPT element documents a script. This element can be displayed several times in the head or body of an HTML document.

And some sample HTML does not look perfectly formatted here :)

  & lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 / /" HT: http: //www.w3 org / TR / HTML4 / strict.dtd "& gt; & gt; HTML & gt; & gt; HEAD & Gt; & lt; TITLE & gt; A document with SCRIPT & lt; / TITLE & gt; & lt; META http-equiv = "content-script-type" content = "text / TCL"> gt; & lt; SCRIPT type = "text / vbscript" src = "http://someplace.com/progs/vbcalc"> gt; script & gt; & lt; / HEAD & gt; & lt; body & gt; & quot; Lt; SCRIPT type = "text / javascript" & gt; ... some javascript ... & lt; / SCRIPT & gt; & lt; / body & gt; & lt; / html & gt;  < / Pre> 

And look forward to doing something like this:

& lt; SCRIPT & gt; : < New async attribute in

Note: The methods [thus] that a script can be executed:

The async attribute is "true": the script The rest of the page will be executed asynchrously, so that the script will be executed while the page is continuing.

The async characteristic is "false", but the deferred attribute is "true": the script will be executed when page parsing Will end with.


Comments