JavaScript/JavaScript within HTML: Difference between revisions
[checked revision] | [checked revision] |
Content deleted Content added
âLinking to external scripts: - This has been deprecated per HTML5 |
No edit summary |
||
Line 1:
<noinclude>{{Prognav|JavaScript|First program|Lexical structure|prog=0}}</noinclude>
=== Inline HTML comment markers ===âŧ
The inline HTML comments are to prevent older browsers that do not understand the {{HTML:element|script}} element from displaying the script code in plain text.âŧ
<source lang=HTML4strict>âŧ
<script type="text/javascript">âŧ
<!--âŧ
// JavaScript code hereâŧ
// -->âŧ
</script>âŧ
</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 "<tt><!--</tt>" and ending with "<tt>--></tt>", effectively ignoring the script completely. If the HTML comment was not there, the entire script would be displayed in plain text to the user by these browsers.âŧ
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 "<tt><!--</tt>". In the above case, the first line of the actual JavaScript code is therefore the line "<tt>// JavaScript code here</tt>".âŧ
The last line of the script, "<tt>// --></tt>", is a one line JavaScript comment that prevents the HTML end comment tag "<tt>--></tt>" from being interpreted as JavaScript.âŧ
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.âŧ
== The {{HTML:element|script}} element ==
Line 39 âļ 58:
</script>
</source>
â˛=== Inline HTML comment markers ===
â˛The inline HTML comments are to prevent older browsers that do not understand the {{HTML:element|script}} element from displaying the script code in plain text.
â˛<source lang=HTML4strict>
â˛<script type="text/javascript">
Ⲡ<!--
Ⲡ// JavaScript code here
Ⲡ// -->
â˛</script>
â˛</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 "<tt><!--</tt>" and ending with "<tt>--></tt>", effectively ignoring the script completely. If the HTML comment was not there, the entire script would be displayed in plain text to the user by these browsers.
â˛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 "<tt><!--</tt>". In the above case, the first line of the actual JavaScript code is therefore the line "<tt>// JavaScript code here</tt>".
â˛The last line of the script, "<tt>// --></tt>", is a one line JavaScript comment that prevents the HTML end comment tag "<tt>--></tt>" from being interpreted as JavaScript.
â˛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.
=== Inline XHTML JavaScript ===
|