script

< html‎ | elements
Jump to: navigation, search

script

This article is Almost Ready.


W3C Candidate Recommendation

Summary

The script element enables dynamic script and data blocks to be included in documents. It can contain code/data directly or it can link to external sources. It is mainly used with JavaScript.


Overview Table

DOM Interface HTMLScriptElement

Standards information

Properties

The script object has these properties.

Property Description Used with inline scripts
src Retrieves the URL to an external file that contains the source code or data. No
type Sets or retrieves the MIME type for the script, the default is text/javascript. You can't use the charset attribute with this attribute. Yes
charset Sets or retrieves the script's character encoding. You can't use the type attribute with this attribute. No
language Sets or retrieves the programming language for the associated scripting engine. Depracated, use type instead. Yes
defer Sets or retrieves the whether or not the script will be loaded asynchronously and executed synchronously. No
async Sets or retrieves the whether or not the script will be loaded asynchronously and executed asynchronously. No
crossorigin Sets or retrieves the whether or not script error information will be revealed from the script(This is used only when scripts are being loaded from different origins). No


Compatibility

Do you think this data can be improved? You can ask to add by opening an issue or make a pull request.

Desktop

FeaturesChromeFirefoxInternet ExplorerOperaSafari
Basic support
1.0
Yes
1.0
Yes
?
Yes
?
Yes
?
Yes
async attribute
?
Yes
?
Unknown
10
Yes
?
none
?
Yes
defer attribute
?
Yes
?
Unknown
4
Yes
?
none
?
Yes
crossorigin attribute
30.0
Yes
?
Unknown
?
none
12.50
Yes
?
Unknown

Mobile

FeaturesAndroidFirefox MobileIE MobileOpera MobileSafari Mobile
Basic support
?
Yes
1.0
Yes
?
Yes
?
Yes
?
Yes
async attribute
?
Yes
1.0
Yes
?
none
?
Unknown
?
Yes
defer attribute
?
Yes
1.0
Yes
?
none
?
Unknown
?
Yes

Examples

Loading an external script.

HTML

<script src="http://example.com/Script/Url/here.js&quot; type="text/javascript"></script>

Writing an inline script.

HTML

<script type="text/javascript">
  //Do stuff...
</script>

Notes

Code within the script block that is not contained within a function is executed immediately as the document is loaded.When the Type attribute is unset on the script object, then text/javascript is used. The order of the script objects in a document can also be important, especially if scripting event handlers are assigned to one or more elements in the document. Using async="async" didn't work in some older browser, instead async="true" was used.



See also

Related articles

HTML


















































… further results

Other articles

<noscript> tag

Related pages (MSDN)

  • XML Data Islands

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]