<script>

  • Revision slug: HTML/Element/Script
  • Revision title: script
  • Revision id: 45694
  • Created:
  • Creator: Hsivonen
  • Is current revision? No
  • Comment Warn against calling document.write() from async and defer scripts.; 121 words added

Revision Content

Summary

The script element is used to embed or reference an executable script within an HTML or XHTML document.

Attributes

async {{ gecko_minversion_inline("1.9.2") }}
This Boolean attribute is set (to the value async) to indicate that the browser should, if possible, execute the script asynchronously. If the script cannot be executed asynchronously, or the browser doesn't support this attribute, the script is executed synchronously (and loading the content blocks until the script finishes running). Never call document.write() from an async script. In Gecko 1.9.2, calling document.write() has an unpredictable effect. In later versions, calling document.write() from an async script is expected to blow away the document.
src
This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.
type
This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. This attribute must be specified per various HTML and XHTML DTDs.
language {{ Deprecated_inline() }}
Like the type attribute, this attribute identifies the scripting language in use. Unlike the type attribute, however, this attribute’s possible values were never standardized. The type attribute should be used instead.
defer {{ gecko_minversion_inline("1.9.1") }}
This Boolean attribute is set (to the value defer) to indicate to a browser that it may continue parsing and rendering a document without waiting for a script to be executed. Since this feature is optional, authors should not assume that the script’s execution will actually be deferred. Never call document.write() from an defer script (since Gecko 1.9.2, this will blow away the document). The defer attribute shouldn't be used on scripts that don't have the src attribute. Since Gecko 1.9.2, the defer attribute is ignored on scripts that don't have the src attribute. However, in Gecko 1.9.1 even inline scripts are deferred if the defer attribute is set.

Revision Source

<h3 id="Summary" name="Summary">Summary</h3>
<p>The <code>script</code> element is used to embed or reference an executable script within an <abbr>HTML</abbr> or <abbr>XHTML</abbr> document.</p>
<ul> <li>Element Type: <a href="/en/HTML/Block-level_elements" title="en/HTML/Block-level_elements">block‐level</a></li> <li>Allowed Content: script content</li>
</ul>
<h3 id="Attributes" name="Attributes">Attributes</h3>
<dl> <dt style="margin-top: 1em;">async {{ gecko_minversion_inline("1.9.2") }}</dt> <dd>This Boolean attribute is set (to the value <code>async</code>) to indicate that the browser should, if possible, execute the script asynchronously. If the script cannot be executed asynchronously, or the browser doesn't support this attribute, the script is executed synchronously (and loading the content blocks until the script finishes running). Never call <code>document.write()</code> from an <code>async</code> script. In Gecko 1.9.2, calling <code>document.write()</code> has an unpredictable effect. In later versions, calling <code>document.write()</code> from an <code>async</code> script is expected to blow away the document.</dd> <dt style="margin-top: 1em;"><code>src</code></dt> <dd>This attribute specifies the <abbr>URI</abbr> of an external script; this can be used as an alternative to embedding a script directly within a document. <code>script</code> elements with an <code>src</code> attribute specified should not have a script embedded within its tags.</dd> <dt style="margin-top: 1em;"><code>type</code></dt> <dd>This attribute identifies the scripting language of code embedded within a <code>script</code> element or referenced via the element’s <code>src</code> attribute. This is specified as a <abbr>MIME type; examples of supported <abbr>MIME types include <code>text/javascript</code>, <code>text/ecmascript</code>, <code>application/javascript</code>, and <code>application/ecmascript</code>. This attribute must be specified per various <abbr>HTML and <abbr>XHTML <abbr>DTDs. </abbr></abbr></abbr></abbr></abbr></dd> <dt style="margin-top: 1em;"><code>language</code> {{ Deprecated_inline() }}</dt> <dd>Like the <code>type</code> attribute, this attribute identifies the scripting language in use. Unlike the <code>type</code> attribute, however, this attribute’s possible values were never standardized. The <code>type</code> attribute should be used instead.</dd> <dt style="margin-top: 1em;"><code>defer</code> {{ gecko_minversion_inline("1.9.1") }}</dt> <dd>This Boolean attribute is set (to the value <code>defer</code>) to indicate to a browser that it <strong>may</strong> continue parsing and rendering a document without waiting for a script to be executed. Since this feature is optional, authors should not assume that the script’s execution will actually be deferred. Never call <code>document.write()</code> from an <code>defer</code> script (since Gecko 1.9.2, this will blow away the document). The <code>defer</code> attribute shouldn't be used on scripts that don't have the <code>src</code> attribute. Since Gecko 1.9.2, the <code>defer</code> attribute is ignored on scripts that don't have the <code>src</code> attribute. However, in Gecko 1.9.1 even inline scripts are deferred if the <code>defer</code> attribute is set.</dd>
</dl>
Revert to this revision