HTML Script Tag
Reference on the HTML Script Tag. Including its useful examples, and a list of the allowed attributes.
The Script Element is used to place scripts in a page, or to load external scripts. Can be used in conjunction with a noscript element. Scripts can be placed any number of times, inside head, and/or body.
According to the standards, user agents should ignore the content of the element, if the src attribute has a URI value. So make sure to either use external scripts, or embedded. Do not use both with the same element!
Default scripting language
As the author, you should make sure to define which scripting language is used. This can either be done locally, with the use of the type attribute, or by declaring a default language throughout the page. The below example is using the type attribute.
<script type="text/javascript"> /* JavaScript to be run */ </script>
You can also declare a default language type, using HTTP Headers.
Content-Script-Type: type
Finally you can also use the http header equivalent meta tag.
<meta http-equiv="Content-Script-Type" content="type">
Attributes
Standard Attributes
| Attribute: | Value: | Description: | DTD: |
| Attrs | Other Attributes | Common, Event, I18n | STF |
| charset | character encoding | The character encoding of the script. | STF |
| type | Content Type | The Content Type of the scripting language used. | STF |
| src | URI | External script location | STF |
| defer | defer | Hints the UA that no content is generated, so it may continiue parsing and rendering. | STF |
DTD. Defines which document type the attribute is allowed. S=Strict, T=Transitional, F=Frameset.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script type="text/javascript" src="/scripts/MyScript.js">
/* External JavaScript, do not embed anything here. */
</script>
</head>
<body>
<script type="text/javascript">
/* Embedded script */
document.write('<p>Welcome to our company website!</p>');
</script>
</body>
</html>