Latest web development tutorials

HTML DOM Script type property

Script Object Reference Script Object

Examples

Get the MIME type of the script:

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

x The output is:

text/javascript

try it"

Definition and Usage

Value of the type property sets or returns the script type property.

type attribute specifies the MIME type of the script.

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

MIME type consists of two parts: media type and subtype. For JavaScript, MIME type is "text / javascript".

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the type attribute.


grammar

Returns type attributes:

scriptObject .type

Setting type attributes:

scriptObject .type=MIME_type

Property Value

描述
MIME_type 规定脚本的 MIME 类型。

一些常用的值:
  • text/javascript (默认)
  • text/ecmascript
  • application/ecmascript
  • application/javascript
  • text/vbscript

请参阅 IANA MIME 类型 ,获得标准 MIME 类型的完整列表。

technical details

return value: String representing the MIME type of the script.


related articles

HTML Reference Manual: HTML <Script> of the type attribute


Script Object Reference Script Object