script type attribute
I. SCRIPTS:
- → the type attribute on the script element allows you to specify the language of the script (for inline and linked scripts)
- is a specific attribute → can be applied ONLY on the next html elements: a, area, button, embed, input, link, menu, menuitem, object, ol, script, source, style
- is optional if the scripting language is text/javascript
- if type attribute is present, charset must be absent
- MIME types interpreted as scripting languages:
- application/ecmascript
- application/javascript
- application/x-ecmascript
- application/x-javascript
- text/ecmascript
- text/javascript
- text/javascript1.0
- text/javascript1.1
- text/javascript1.2
- text/javascript1.3
- text/javascript1.4
- text/javascript1.5
- text/jscript
- text/livescript
- text/x-ecmascript
- text/x-javascript
- ...
II. DATA ISLANDS:
- → the type attribute on the script element allows you to specify the format type of the stored data (inline data);
- is always required for data blocks ⁄data islands
- MIME types not interpreted as scripting languages, suitable for data islands:
- text/plain
- text/xml
- application/xml
- application/octet-stream
Examples
< | attribute | = | "value(s)" | > | ... | </ | >Examples |
---|---|---|---|---|---|---|---|
5. | type | = | MIME type | < inline javascript statements here <⁄ > ⁄⁄ INLINE script <type="application/javascript"> inline javascript statements here <⁄ > ⁄⁄ INLINE script <src="file.js" type="application/javascript"> <⁄ > ⁄⁄ EXTERNAL script <type="text/xml"> inline xml goes here <⁄ > ⁄⁄ DATA ISLAND <type="text/plain"> inline plain text goes here <⁄ > ⁄⁄ DATA ISLAND | >
Video demonstration script type attribute
HTML5 script type attribute, Tutorial
min | video details |
---|---|
00:06 | the type attribute on the script element allows you to: |
00:06 | 1. specify the language of the INLINE script |
00:09 | 2. specify the language of the EXTERNAL script |
00:12 | 3. specify the format type of the STORED DATA (data islands) |
00:24 | 1. the language of this INLINE script is JavaScript; corresponding MIME type: text/javascript |
00:35 | 2. the language of this EXTERNAL script is JavaScript; corresponding MIME type: text/javascript |
00:46 | 3. the format type of the stored data is: xml; corresponding MIME type: text/xml |
00:59 | Case: INLINE and EXTERNAL SCRIPTS - the type attribute may be omitted if the scripting language is JavaScript (text/javascript) represents the default MIME type |
01:07 | Case: DATA ISLANDS: - the type attribute is required |
01:11 | Case: INLINE SCRIPTS and DATA ISLANDS - the charset attribute must be specified (because src attribute absent) |