JavaScript/JavaScript within HTML: Difference between revisions
[checked revision] | [checked revision] |
Content deleted Content added
m Sae1962 moved page JavaScript/Placing the Code to JavaScript/Placing the code: Moved to new name |
m Minor edits |
||
Line 1:
<noinclude>{{Prognav|JavaScript|First
== The {{HTML:element|script}} element ==
Line 29:
</source>
While the <
== Inline JavaScript ==
Line 51:
</source>
Older browsers that do not understand the {{HTML:element|script}} element will interpret the entire content of the {{HTML:element|script}} element above as one single HTML comment, beginning with "<
Current browsers that know about the {{HTML:element|script}} element will ignore the ''first'' line of a {{HTML:element|script}} element, if it starts with "<
The last line of the script, "<
The use of comment markers is rarely required nowadays, as the browsers that do not recognise the {{HTML:element|script}} element are virtually non-existent. These early browsers were Mosaic, Netscape 1, and Internet Explorer 2. From Netscape 2.0 in December 1995 and Internet Explorer 3.0 in August 1996 onward, those browsers were able to interpret JavaScript.<ref>[[w:JavaScript#History and naming]]</ref> Any modern browser that doesn't support JavaScript will still recognize the <script> tag and not display it to the user.
Line 70:
</source>
Note that the <
== Linking to external scripts ==
JavaScript is commonly stored in a file so that it may be used by many web pages on your site. This makes it much easier for updates to occur and saves space on your server. This method is recommended for [http://alistapart.com/articles/behavioralseparation separating behavior] (JavaScript) from content ((X)HTML) and it prevents the issue of incompatibility with inline comments in XHTML and HTML.
Add <
Because the server provides the content type when the file is requested, specifying the type is optional when linking to external scripts. It's still advised to specify the type as <
<source lang=HTML4strict>
Line 84:
== Location of script elements ==
The <
A standard location is within the {{HTML:element|head}} element. Placement within the {{HTML:element|body}} however is allowed.
Line 101:
</source>
There are however some best practices for speeding up your web site <ref>Yahoo: [http://developer.yahoo.com/performance/rules.html best practices for speeding up your web site]</ref> from the Yahoo! Developer Network that specify a different placement for scripts, to [http://developer.yahoo.com/performance/rules.html#js_bottom put scripts at the bottom], just before the <
<source lang=HTML5>
Line 120:
== Reference ==
<references/>
<noinclude>{{Prognav|JavaScript|First
{{BookCat}}
|