Script typeProperties

Script 对象参考手册Script Object

Example

Get the MIME type of a script:

var x = document.getElementById("myScript").type

xThe output is:

text/javascript

Try it Yourself »

Definition and Usage

The type attribute sets or returns the value of the type attribute of a script.

The type attribute specifies the MIME type of a script.

The type attribute identifies the content between the <script> and </script> tags.

MIME types consist of two parts: a media type and a subtype. For JavaScript, the MIME type is "text/javascript".

Note:In HTML5, the type attribute is no longer required. The default value is "text/javascript".


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the type attribute.


Syntax

Return the type attribute:

scriptObject.type

Set the type attribute:

scriptObject.type=MIME_type

Property Values

Value Description
MIME_type Specifies the MIME type of a script.

Some common values:
  • text/javascript (default)
  • text/ecmascript
  • application/ecmascript
  • application/javascript
  • text/vbscript

See alsoIANA MIME types, for a complete list of standard MIME types.

Technical Details

Return Value: A string, representing the MIME type of the script.


Related Articles

HTML Reference Manual:HTML <script> type Attribute


Script 对象参考手册Script Object

Other Extensions