Annotation of html5/spec-author-view/scripting-1.html, revision 1.71
1.53 mike 1: <!DOCTYPE html><!-- when publishing, change bits marked ZZZ --><html class="split chapter" lang="en-US-x-Hixie"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><title>4.3 Scripting — HTML5 (Edition for Web Authors)</title><link href="whatwg.css" rel="stylesheet"><style type="text/css">
1.9 mike 2: pre { margin-left: 2em; white-space: pre-wrap; }
3: h2 { margin: 3em 0 1em 0; }
4: h3 { margin: 2.5em 0 1em 0; }
5: h4 { margin: 2.5em 0 0.75em 0; }
6: h5, h6 { margin: 2.5em 0 1em; }
7: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
8: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
9: p { margin: 1em 0; }
10: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
11: dl, dd { margin-top: 0; margin-bottom: 0; }
12: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
13: dt + dt { margin-top: 0; }
14: dd dt { margin-top: 0.25em; margin-bottom: 0; }
15: dd p { margin-top: 0; }
16: dd dl + p { margin-top: 1em; }
17: dd table + p { margin-top: 1em; }
18: p + * > li, dd li { margin: 1em 0; }
19: dt, dfn { font-weight: bold; font-style: normal; }
20: dt dfn { font-style: italic; }
21: pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
22: pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
23: pre em { font-weight: bolder; font-style: normal; }
24: @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
25: var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
26: table { border-collapse: collapse; border-style: hidden hidden none hidden; }
1.32 mike 27: table thead, table tbody { border-bottom: solid; }
1.9 mike 28: table tbody th:first-child { border-left: solid; }
29: table tbody th { text-align: left; }
30: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
31: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
32:
33: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
34: .matrix, .matrix td { border: none; text-align: right; }
35: .matrix { margin-left: 2em; }
36: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
37: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
38: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
39:
40: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
41: img.extra { float: right; }
42: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
43: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
44: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
45: pre.css:first-line { color: #AAAA50; }
1.17 mike 46: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
1.9 mike 47: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
48: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
49: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
50: dl.domintro dd p { margin: 0.5em 0; }
51: dl.switch { padding-left: 2em; }
52: dl.switch > dt { text-indent: -1.5em; }
53: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
54: dl.triple { padding: 0 0 0 1em; }
55: dl.triple dt, dl.triple dd { margin: 0; display: inline }
56: dl.triple dt:after { content: ':'; }
57: dl.triple dd:after { content: '\A'; white-space: pre; }
58: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
59: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
60: a .diff-new { border-bottom: 1px blue solid; }
61:
62: h2 { page-break-before: always; }
63: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
64: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
65:
66: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
67:
68: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
69: div.head p { margin: 0; }
70: div.head h1 { margin: 0; }
71: div.head .logo { float: right; margin: 0 1em; }
72: div.head .logo img { border: none } /* remove border from top image */
73: div.head dl { margin: 1em 0; }
74: div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
75:
76: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
77: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
78: body > .toc > li > * { margin-bottom: 0.5em; }
79: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
80: .toc, .toc li { list-style: none; }
81:
82: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
83: .brief li { margin: 0; padding: 0; }
84: .brief li p { margin: 0; padding: 0; }
85:
86: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
87: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
88: .category-list li { display: inline; }
89: .category-list li:not(:last-child)::after { content: ', '; }
90: .category-list li > span, .category-list li > a { text-transform: lowercase; }
91: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
92:
93: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
94: .XXX > :first-child { margin-top: 0; }
95: p .XXX { line-height: 3em; }
96: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
97: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
98: .annotation :link, .annotation :visited { color: inherit; }
99: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
100: .annotation span { border: none ! important; }
101: .note { color: green; background: transparent; font-family: sans-serif; }
102: .warning { color: red; background: transparent; }
103: .note, .warning { font-weight: bolder; font-style: italic; }
104: p.note, div.note { padding: 0.5em 2em; }
105: span.note { padding: 0 2em; }
106: .note p:first-child, .warning p:first-child { margin-top: 0; }
107: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
108: .warning:before { font-style: normal; }
109: p.note:before { content: 'Note: '; }
110: p.warning:before { content: '\26A0 Warning! '; }
111:
112: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
113: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
114: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
115:
116: h4 { position: relative; z-index: 3; }
117: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
118: .element {
119: background: #EEEEFF;
120: color: black;
121: margin: 0 0 1em 0.15em;
122: padding: 0 1em 0.25em 0.75em;
123: border-left: solid #9999FF 0.25em;
124: position: relative;
125: z-index: 1;
126: }
127: .element:before {
128: position: absolute;
129: z-index: 2;
130: top: 0;
131: left: -1.15em;
132: height: 2em;
133: width: 0.9em;
134: background: #EEEEFF;
135: content: ' ';
136: border-style: none none solid solid;
137: border-color: #9999FF;
138: border-width: 0.25em;
139: }
140:
141: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
142: td > .example:only-child { margin: 0 0 0 0.1em; }
143:
144: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
145: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
146: ul.domTree li li { list-style: none; }
147: ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
148: ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
149: ul.domTree span { font-style: italic; font-family: serif; }
150: ul.domTree .t1 code { color: purple; font-weight: bold; }
151: ul.domTree .t2 { font-style: normal; font-family: monospace; }
152: ul.domTree .t2 .name { color: black; font-weight: bold; }
153: ul.domTree .t2 .value { color: blue; font-weight: normal; }
154: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
155: ul.domTree .t7 code, .domTree .t8 code { color: green; }
156: ul.domTree .t10 code { color: teal; }
157:
1.13 mike 158: body.dfnEnabled dfn { cursor: pointer; }
159: .dfnPanel {
160: display: inline;
161: position: absolute;
162: z-index: 10;
163: height: auto;
164: width: auto;
165: padding: 0.5em 0.75em;
166: font: small sans-serif, Droid Sans Fallback;
167: background: #DDDDDD;
168: color: black;
169: border: outset 0.2em;
170: }
171: .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
172: .dfnPanel :link, .dfnPanel :visited { color: black; }
173: .dfnPanel p { font-weight: bolder; }
174: .dfnPanel * + p { margin-top: 0.25em; }
175: .dfnPanel li { list-style-position: inside; }
176:
1.9 mike 177: #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
178: #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
179: #configUI p label { display: block; }
180: #configUI #updateUI, #configUI .loginUI { text-align: center; }
181: #configUI input[type=button] { display: block; margin: auto; }
182: </style><style type="text/css">
183:
184: .applies thead th > * { display: block; }
185: .applies thead code { display: block; }
186: .applies tbody th { whitespace: nowrap; }
187: .applies td { text-align: center; }
188: .applies .yes { background: yellow; }
189:
190: .matrix, .matrix td { border: none; text-align: right; }
191: .matrix { margin-left: 2em; }
192:
193: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
194: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
195: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
196:
197: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
198: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
199: #table-example-1 caption { padding-bottom: 0.5em; }
200: #table-example-1 thead, #table-example-1 tbody { border: none; }
201: #table-example-1 th, #table-example-1 td { border: solid thin; }
202: #table-example-1 th { font-weight: normal; }
203: #table-example-1 td { border-style: none solid; vertical-align: top; }
204: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
205: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
206: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
207: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
208: #table-example-1 tbody td:first-child::after { content: leader(". "); }
209: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
210: #table-example-1 tbody td:first-child + td { width: 10em; }
211: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
212: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
213:
214: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
215: .apple-table-examples * { font-family: "Times", serif; }
216: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
217: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
218: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
219: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
220: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
221: .apple-table-examples td { text-align: right; vertical-align: top; }
222: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
1.11 mike 223: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
224: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
225: .apple-table-examples sup { line-height: 0; }
226:
1.12 mike 227: .details-example img { vertical-align: top; }
228:
1.22 mike 229: #named-character-references-table {
230: font-size: 0.6em;
231: column-width: 28em;
232: column-gap: 1em;
233: -moz-column-width: 28em;
234: -moz-column-gap: 1em;
235: -webkit-column-width: 28em;
236: -webkit-column-gap: 1em;
237: }
238: #named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
239: #named-character-references-table > table > tbody > tr > td:last-child:hover > span { position: absolute; top: auto; left: auto; margin-left: 0.5em; line-height: 1.2; font-size: 5em; border: outset; padding: 0.25em 0.5em; background: white; width: 1.25em; height: auto; text-align: center; }
240:
1.33 mike 241: .glyph.control { color: red; }
242:
1.36 mike 243: @font-face {
244: font-family: 'Essays1743';
245: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
246: }
247: @font-face {
248: font-family: 'Essays1743';
249: font-weight: bold;
250: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
251: }
252: @font-face {
253: font-family: 'Essays1743';
254: font-style: italic;
255: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
256: }
257: @font-face {
258: font-family: 'Essays1743';
259: font-style: italic;
260: font-weight: bold;
261: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
262: }
263:
1.21 mike 264: </style><link href="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script type="text/javascript">
1.11 mike 265: function getCookie(name) {
266: var params = location.search.substr(1).split("&");
267: for (var index = 0; index < params.length; index++) {
268: if (params[index] == name)
269: return "1";
270: var data = params[index].split("=");
271: if (data[0] == name)
272: return unescape(data[1]);
273: }
274: var cookies = document.cookie.split("; ");
275: for (var index = 0; index < cookies.length; index++) {
276: var data = cookies[index].split("=");
277: if (data[0] == name)
278: return unescape(data[1]);
279: }
280: return null;
281: }
282: function load(script) {
283: var e = document.createElement('script');
284: e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
285: document.body.appendChild(e);
286: }
287: function init() {
288: if (location.search == '?slow-browser')
289: return;
290: var configUI = document.createElement('div');
291: configUI.id = 'configUI';
292: document.body.appendChild(configUI);
293: // load('reviewer.js'); // would need cross-site XHR
294: if (document.getElementById('head'))
295: load('toc.js');
296:
297: // load('updater.js'); // would need cross-site XHR
1.12 mike 298: load('dfn.js'); // doesn't support split-out specs, but, oh well.
1.11 mike 299: // load('status.js'); // would need cross-site XHR
300: if (getCookie('profile') == '1')
301: document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
302: fixBrokenLink();
303: }
1.52 mike 304: </script><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><link href="style.css" rel="stylesheet"><script src="link-fixup.js"></script><link href="semantics.html" rel="prev" title="4 The elements of HTML">
1.46 mike 305: <link href="Overview.html#contents" rel="index" title="Table of contents">
306: <link href="sections.html" rel="next" title="4.4 Sections">
307: <body onload="fixBrokenLink(); init()"><div class="head" id="head">
1.11 mike 308: <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.34 mike 309:
1.71 ! mike 310: <h1>HTML5 (Edition for Web Authors)<span class="rcsrevision"> revision 1.4129</span></h1>
1.11 mike 311: </div><div>
1.46 mike 312: <a href="semantics.html">← 4 The elements of HTML</a> –
313: <a href="Overview.html#contents">Table of contents</a> –
314: <a href="sections.html">4.4 Sections →</a>
1.11 mike 315: <ol class="toc"><li><ol><li><a href="scripting-1.html#scripting-1"><span class="secno">4.3 </span>Scripting</a>
316: <ol><li><a href="scripting-1.html#script"><span class="secno">4.3.1 </span>The <code>script</code> element</a>
1.46 mike 317: <ol><li><a href="scripting-1.html#scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</a><li><a href="scripting-1.html#restrictions-for-contents-of-script-elements"><span class="secno">4.3.1.2 </span>Restrictions for contents of <code>script</code> elements</a><li><a href="scripting-1.html#inline-documentation-for-external-scripts"><span class="secno">4.3.1.3 </span>Inline documentation for external scripts</a></ol><li><a href="scripting-1.html#the-noscript-element"><span class="secno">4.3.2 </span>The <code>noscript</code> element</a></ol></ol></ol></div>
1.11 mike 318:
1.46 mike 319: <h3 id="scripting-1"><span class="secno">4.3 </span>Scripting</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i><p>Scripts allow authors to add interactivity to their documents.<p>Authors are encouraged to use declarative alternatives to
1.11 mike 320: scripting where possible, as declarative mechanisms are often more
1.46 mike 321: maintainable, and many users disable scripting.<div class="example">
1.11 mike 322: <p>For example, instead of using script to show or hide a section
323: to show more details, the <code><a href="interactive-elements.html#the-details-element">details</a></code> element could be
324: used.</p>
325: </div><p>Authors are also encouraged to make their applications degrade
1.46 mike 326: gracefully in the absence of scripting support.<div class="example">
1.11 mike 327: <p>For example, if an author provides a link in a table header to
328: dynamically resort the table, the link could also be made to
329: function without scripts by requesting the sorted table from the
330: server.</p>
1.46 mike 331: </div><h4 id="script"><span class="secno">4.3.1 </span>The <dfn><code>script</code></dfn> element</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i><dl class="element"><dt>Categories</dt>
1.11 mike 332: <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
333: <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
334: <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
335: <dt>Contexts in which this element may be used:</dt>
336: <dd>Where <a href="content-models.html#metadata-content">metadata content</a> is expected.</dd>
337: <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected.</dd>
338: <dt>Content model:</dt>
339: <dd>If there is no <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
340: attribute, depends on the value of the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, but must match
341: <a href="#restrictions-for-contents-of-script-elements">script content restrictions</a>.</dd>
342: <dd>If there <em>is</em> a <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
343: attribute, the element must be either empty or contain only
344: <a href="#inline-documentation-for-external-scripts">script documentation</a> that also matches <a href="#restrictions-for-contents-of-script-elements">script
345: content restrictions</a>.</dd>
346: <dt>Content attributes:</dt>
347: <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
348: <dd><code title="attr-script-src"><a href="#attr-script-src">src</a></code></dd>
349: <dd><code title="attr-script-async"><a href="#attr-script-async">async</a></code></dd>
350: <dd><code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code></dd>
351: <dd><code title="attr-script-type"><a href="#attr-script-type">type</a></code></dd>
352: <dd><code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code></dd>
353: <dt>DOM interface:</dt>
354: <dd>
355: <pre class="idl">interface <dfn id="htmlscriptelement">HTMLScriptElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
1.46 mike 356: attribute DOMString <a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-src" title='Read about this "src" reference in the full HTML5 spec.'>src</a>;
357: attribute boolean <a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-async" title='Read about this "async" reference in the full HTML5 spec.'>async</a>;
358: attribute boolean <a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-defer" title='Read about this "defer" reference in the full HTML5 spec.'>defer</a>;
359: attribute DOMString <a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-type" title='Read about this "type" reference in the full HTML5 spec.'>type</a>;
360: attribute DOMString <a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-charset" title='Read about this "charset" reference in the full HTML5 spec.'>charset</a>;
361: attribute DOMString <a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-text" title='Read about this "text" reference in the full HTML5 spec.'>text</a>;
1.11 mike 362: };</pre>
363: </dd>
364: </dl><p>The <code><a href="#script">script</a></code> element allows authors to include dynamic
365: script and data blocks in their documents. The element does not
1.46 mike 366: <a class="full-spec-link" href="http://dev.w3.org/html5/spec/rendering.html#represents" title='Read about this "represent" reference in the full HTML5 spec.'>represent</a> content for the user.<p>When used to include dynamic scripts, the scripts may either be
1.11 mike 367: embedded inline or may be imported from an external file using the
368: <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute. If the language
369: is not that described by "<code title="">text/javascript</code>",
370: then the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute must
1.46 mike 371: be present, as described below.<p>When used to include data blocks (as opposed to scripts), the
1.22 mike 372: data must be embedded inline, the format of the data must be given
373: using the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, and
374: the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute must not be
1.46 mike 375: specified.<p>The <dfn id="attr-script-type" title="attr-script-type"><code>type</code></dfn>
1.11 mike 376: attribute gives the language of the script or format of the data. If
377: the attribute is present, its value must be a <a href="infrastructure.html#valid-mime-type">valid MIME
1.12 mike 378: type</a>. The <code title="">charset</code> parameter must not be
1.14 mike 379: specified. The default, which is used if the attribute is absent,
1.46 mike 380: is "<code title="">text/javascript</code>".<p>The <dfn id="attr-script-src" title="attr-script-src"><code>src</code></dfn>
1.11 mike 381: attribute, if specified, gives the address of the external script
1.31 mike 382: resource to use. The value of the attribute must be a <a href="urls.html#valid-non-empty-url-potentially-surrounded-by-spaces">valid
383: non-empty URL potentially surrounded by spaces</a> identifying a
384: script resource of the type given by the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, if the attribute is
385: present, or of the type "<code title="">text/javascript</code>", if
386: the attribute is absent. A resource is a script resource of a given
387: type if that type identifies a scripting language and the resource
1.46 mike 388: conforms with the requirements of that language's specification.<p>The <dfn id="attr-script-charset" title="attr-script-charset"><code>charset</code></dfn>
1.11 mike 389: attribute gives the character encoding of the external script
390: resource. The attribute must not be specified if the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is not present. If the
391: attribute is set, its value must be a valid character encoding name,
392: must be an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the
393: <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> for that encoding, and must match
394: the encoding given in the <code title="">charset</code> parameter of
1.46 mike 395: the <a class="full-spec-link" href="http://dev.w3.org/html5/spec/fetching-resources.html#content-type" title='Read about this "Content-Type metadata" reference in the full HTML5 spec.'>Content-Type metadata</a> of the
396: external file, if any. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a><p>The <dfn id="attr-script-async" title="attr-script-async"><code>async</code></dfn> and
1.11 mike 397: <dfn id="attr-script-defer" title="attr-script-defer"><code>defer</code></dfn> attributes
398: are <a href="common-microsyntaxes.html#boolean-attribute" title="boolean attribute">boolean attributes</a> that
1.29 mike 399: indicate how the script should be executed. The <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> and <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attributes must not be
400: specified if the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute
1.46 mike 401: is not present.<p>There are three possible modes that can be selected using these
1.11 mike 402: attributes. If the <code title="attr-script-async"><a href="#attr-script-async">async</a></code>
403: attribute is present, then the script will be executed
404: asynchronously, as soon as it is available. If the <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute is not present but
405: the <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute is
406: present, then the script is executed when the page has finished
407: parsing. If neither attribute is present, then the script is
408: fetched and executed immediately, before the user agent continues
1.46 mike 409: parsing the page.<p class="note">The exact processing details for these attributes
1.20 mike 410: are, for mostly historical reasons, somewhat non-trivial, involving
411: a number of aspects of HTML. The implementation requirements are
412: therefore by necessity scattered throughout the specification. The
413: algorithms below (in this section) describe the core of this
414: processing, but these algorithms reference and are referenced by the
1.46 mike 415: parsing rules for <code><a href="#script">script</a></code> <a class="full-spec-link" href="http://dev.w3.org/html5/spec/tokenization.html#scriptTag" title='Read about this "start" reference in the full HTML5 spec.'>start</a>
416: and <a class="full-spec-link" href="http://dev.w3.org/html5/spec/tokenization.html#scriptEndTag" title='Read about this "end" reference in the full HTML5 spec.'>end</a> tags in HTML, <a class="full-spec-link" href="http://dev.w3.org/html5/spec/tokenization.html#scriptForeignEndTag" title='Read about this "in foreign content" reference in the full HTML5 spec.'>in foreign content</a>, and <a class="full-spec-link" href="http://dev.w3.org/html5/spec/the-xhtml-syntax.html#scriptTagXML" title='Read about this "in XML" reference in the full HTML5 spec.'>in XML</a>, the rules for the <code title="dom-document-write"><a class="full-spec-link" href="http://dev.w3.org/html5/spec/apis-in-html-documents.html#dom-document-write" title='Read about this "document.write()" reference in the full HTML5 spec.'>document.write()</a></code> method, the
417: handling of <a href="webappapis.html#scripting">scripting</a>, etc.<p>The <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute may be
1.11 mike 418: specified even if the <code title="attr-script-async"><a href="#attr-script-async">async</a></code>
419: attribute is specified, to cause legacy Web browsers that only
420: support <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> (and not <code title="attr-script-async"><a href="#attr-script-async">async</a></code>) to fall back to the <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> behavior instead of the
1.46 mike 421: synchronous blocking behavior that is the default.<p>Changing the <code title="attr-script-src"><a href="#attr-script-src">src</a></code>, <code title="attr-script-type"><a href="#attr-script-type">type</a></code>, <code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code>, <code title="attr-script-async"><a href="#attr-script-async">async</a></code>, and <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attributes dynamically has no
1.12 mike 422: direct effect; these attribute are only used at specific times
423: described below.</p><!-- by implication, changes to the base URL
1.46 mike 424: also have no effect --><dl class="domintro"><dt><var title="">script</var> . <code title="dom-script-text"><a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-text" title='Read about this "text" reference in the full HTML5 spec.'>text</a></code> [ = <var title="">value</var> ]</dt>
1.11 mike 425:
426: <dd>
427:
428: <p>Returns the contents of the element, ignoring child nodes that
429: aren't <a href="infrastructure.html#text-node" title="text node">text nodes</a>.</p>
430:
431: <p>Can be set, to replace the element's children with the given
432: value.</p>
433:
434: </dd>
435:
1.46 mike 436: </dl><p class="note">When inserted using the <code title="dom-document-write"><a class="full-spec-link" href="http://dev.w3.org/html5/spec/apis-in-html-documents.html#dom-document-write" title='Read about this "document.write()" reference in the full HTML5 spec.'>document.write()</a></code> method,
1.11 mike 437: <code><a href="#script">script</a></code> elements execute (typically synchronously), but
438: when inserted using <code title="dom-innerHTML"><a href="apis-in-html-documents.html#dom-innerhtml">innerHTML</a></code> and <code title="dom-outerHTML"><a href="apis-in-html-documents.html#dom-outerhtml">outerHTML</a></code> attributes, they do not
1.46 mike 439: execute at all.<div class="example">
1.11 mike 440:
441: <p>In this example, two <code><a href="#script">script</a></code> elements are used. One
442: embeds an external script, and the other includes some data.</p>
443:
444: <pre><script src="game-engine.js"></script>
445: <script type="text/x-game-map">
446: ........U.........e
447: o............A....e
448: .....A.....AAA....e
449: .A..AAA...AAAAA...e
450: </script></pre>
451:
452: <p>The data in this case might be used by the script to generate
453: the map of a video game. The data doesn't have to be used that way,
454: though; maybe the map data is actually embedded in other parts of
455: the page's markup, and the data block here is just used by the
456: site's search engine to help users who are looking for particular
457: features in their game maps.</p>
458:
459: </div><div class="example">
460:
461: <p>The following sample shows how a script element can be used to
462: define a function that is then used by other parts of the
463: document. It also shows how a <code><a href="#script">script</a></code> element can be
464: used to invoke script while the document is being parsed, in this
465: case to initialize the form's output.</p>
466:
467: <pre><script>
468: function calculate(form) {
469: var price = 52000;
470: if (form.elements.brakes.checked)
471: price += 1000;
472: if (form.elements.radio.checked)
473: price += 2500;
474: if (form.elements.turbo.checked)
475: price += 5000;
476: if (form.elements.sticker.checked)
477: price += 250;
478: form.elements.result.value = price;
479: }
480: </script>
481: <form name="pricecalc" onsubmit="return false">
482: <fieldset>
483: <legend>Work out the price of your car</legend>
1.46 mike 484: <p>Base cost: £52000.</p>
1.11 mike 485: <p>Select additional options:</p>
486: <ul>
1.46 mike 487: <li><label><input type=checkbox name=brakes> Ceramic brakes (£1000)</label></li>
488: <li><label><input type=checkbox name=radio> Satellite radio (£2500)</label></li>
489: <li><label><input type=checkbox name=turbo> Turbo charger (£5000)</label></li>
490: <li><label><input type=checkbox name=sticker> "XZ" sticker (£250)</label></li>
1.11 mike 491: </ul>
1.46 mike 492: <p>Total: £<output name=result onformchange="calculate(form)"></output></p>
1.11 mike 493: </fieldset>
494: <script>
495: document.forms.pricecalc.dispatchFormChange();
496: </script>
497: </form></pre>
498:
1.46 mike 499: </div><h5 id="scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i><p>The following lists some <a href="infrastructure.html#mime-type">MIME type</a> strings and the
500: languages to which they refer:<dl><dt>"<code>application/ecmascript</code>"</dt>
1.11 mike 501: <dt>"<code>application/javascript</code>"</dt>
502: <dt>"<code>application/x-ecmascript</code>"</dt>
503: <dt>"<code>application/x-javascript</code>"</dt>
504: <dt>"<code>text/ecmascript</code>"</dt>
505: <dt>"<code>text/javascript</code>"</dt>
506: <dt>"<code>text/javascript1.0</code>"</dt>
507: <dt>"<code>text/javascript1.1</code>"</dt>
508: <dt>"<code>text/javascript1.2</code>"</dt>
509: <dt>"<code>text/javascript1.3</code>"</dt>
510: <dt>"<code>text/javascript1.4</code>"</dt>
511: <dt>"<code>text/javascript1.5</code>"</dt>
512: <dt>"<code>text/jscript</code>"</dt>
513: <dt>"<code>text/livescript</code>"</dt>
514: <dt>"<code>text/x-ecmascript</code>"</dt>
515: <dt>"<code>text/x-javascript</code>"</dt>
1.26 mike 516: <dd>JavaScript. <a href="references.html#refsECMA262">[ECMA262]</a></dd>
1.11 mike 517:
518: <dt>"<code>text/javascript;e4x=1</code>"</dt>
1.26 mike 519: <dd>JavaScript with ECMAScript for XML. <a href="references.html#refsECMA357">[ECMA357]</a></dd>
1.11 mike 520:
1.46 mike 521: </dl><h5 id="restrictions-for-contents-of-script-elements"><span class="secno">4.3.1.2 </span><dfn title="script content restrictions">Restrictions for contents of <code>script</code> elements</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i><p>The <code><a class="full-spec-link" href="http://dev.w3.org/html5/spec/infrastructure.html#textcontent" title='Read about this "textContent" reference in the full HTML5 spec.'>textContent</a></code> of a <code><a href="#script">script</a></code> element must match the
1.11 mike 522: <code title="">script</code> production in the following ABNF, the
1.46 mike 523: character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a><pre>script = data1 *( escape [ script-start data3 ] "-->" data1 ) [ escape ]
1.11 mike 524: escape = "<!--" data2 *( script-start data3 script-end data2 )
525:
526: data1 = <any string that doesn't contain a substring that matches not-data1>
527: not-data1 = <!-- script-end / -->"<!--" <!-- the script-end is redundant here since it would close the element -->
528:
529: data2 = <any string that doesn't contain a substring that matches not-data2>
530: not-data2 = <!-- script-end / -->script-start / "-->" <!-- the script-end is redundant here since it would close the element -->
531:
532: data3 = <any string that doesn't contain a substring that matches not-data3>
533: not-data3 = script-end / "-->"
534:
535: script-start = lt s c r i p t tag-end
536: script-end = lt slash s c r i p t tag-end
537:
538: lt = %x003C ; U+003C LESS-THAN SIGN character (<)
539: slash = %x002F ; U+002F SOLIDUS character (/)
540:
541: s = %x0053 ; U+0053 LATIN CAPITAL LETTER S
542: s =/ %x0073 ; U+0073 LATIN SMALL LETTER S
543: c = %x0043 ; U+0043 LATIN CAPITAL LETTER C
544: c =/ %x0063 ; U+0063 LATIN SMALL LETTER C
545: r = %x0052 ; U+0052 LATIN CAPITAL LETTER R
546: r =/ %x0072 ; U+0072 LATIN SMALL LETTER R
547: i = %x0049 ; U+0049 LATIN CAPITAL LETTER I
548: i =/ %x0069 ; U+0069 LATIN SMALL LETTER I
549: p = %x0050 ; U+0050 LATIN CAPITAL LETTER P
550: p =/ %x0070 ; U+0070 LATIN SMALL LETTER P
551: t = %x0054 ; U+0054 LATIN CAPITAL LETTER T
552: t =/ %x0074 ; U+0074 LATIN SMALL LETTER T
553:
554: tag-end = %x0009 ; U+0009 CHARACTER TABULATION
555: tag-end =/ %x000A ; U+000A LINE FEED (LF)
556: tag-end =/ %x000C ; U+000C FORM FEED (FF)
557: tag-end =/ %x0020 ; U+0020 SPACE
558: tag-end =/ %x002F ; U+002F SOLIDUS (/)
559: tag-end =/ %x003E ; U+003E GREATER-THAN SIGN (>)</pre><p>When a <code><a href="#script">script</a></code> element contains <a href="#inline-documentation-for-external-scripts">script
560: documentation</a>, there are further restrictions on the contents
1.46 mike 561: of the element, as described in the section below.<h5 id="inline-documentation-for-external-scripts"><span class="secno">4.3.1.3 </span><dfn title="script documentation">Inline documentation for external scripts</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i><p>If a <code><a href="#script">script</a></code> element's <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is specified, then the
1.11 mike 562: contents of the <code><a href="#script">script</a></code> element, if any, must be such
1.46 mike 563: that the value of the <code title="dom-script-text"><a class="full-spec-link" href="http://dev.w3.org/html5/spec/scripting-1.html#dom-script-text" title='Read about this "text" reference in the full HTML5 spec.'>text</a></code> IDL
1.11 mike 564: attribute, which is derived from the element's contents, matches the
565: <code title="">documentation</code> production in the following
1.46 mike 566: ABNF, the character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a><pre>documentation = *( *( space / tab / comment ) [ line-comment ] newline )
1.11 mike 567: comment = slash star *( not-star / star not-slash ) 1*star slash
568: line-comment = slash slash *not-newline
569:
570: ; characters
571: tab = %x0009 ; U+0009 TAB
572: newline = %x000A ; U+000A LINE FEED (LF)
573: space = %x0020 ; U+0020 SPACE
574: star = %x002A ; U+002A ASTERISK (*)
575: slash = %x002F ; U+002F SOLIDUS (/)
576: not-newline = %x0000-0009 / %x000B-10FFFF
577: ; a Unicode character other than U+000A LINE FEED (LF)
578: not-star = %x0000-0029 / %x002B-10FFFF
579: ; a Unicode character other than U+002A ASTERISK (*)
580: not-slash = %x0000-002E / %x0030-10FFFF
581: ; a Unicode character other than U+002F SOLIDUS (/)</pre><p class="note">This corresponds to putting the contents of the
1.46 mike 582: element in JavaScript comments.<p class="note">This requirement is in addition to the earlier
1.11 mike 583: restrictions on the syntax of contents of <code><a href="#script">script</a></code>
1.46 mike 584: elements.<div class="example">
1.11 mike 585:
586: <p>This allows authors to include documentation, such as license
587: information or API information, inside their documents while still
588: referring to external script files. The syntax is constrained so
589: that authors don't accidentally include what looks like valid
590: script while also providing a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute.</p>
591:
592: <pre><script src="cool-effects.js">
593: // create new instances using:
594: // var e = new Effect();
595: // start the effect using .play, stop using .stop:
596: // e.play();
597: // e.stop();
598: </script></pre>
599:
1.46 mike 600: </div><h4 id="the-noscript-element"><span class="secno">4.3.2 </span>The <dfn><code>noscript</code></dfn> element</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i><dl class="element"><dt>Categories</dt>
1.11 mike 601: <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
602: <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
603: <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
604: <dt>Contexts in which this element may be used:</dt>
605: <dd>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element of an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>, if there are no ancestor <code><a href="#the-noscript-element">noscript</a></code> elements.</dd>
606: <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected in <a href="dom.html#html-documents">HTML documents</a>, if there are no ancestor <code><a href="#the-noscript-element">noscript</a></code> elements.</dd>
607: <dt>Content model:</dt>
1.46 mike 608: <dd>When <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-noscript" title='Read about this "scripting is disabled" reference in the full HTML5 spec.'>scripting is disabled</a>, in a <code><a href="semantics.html#the-head-element-0">head</a></code> element: in any order, zero or more <code><a href="semantics.html#the-link-element">link</a></code> elements, zero or more <code><a href="semantics.html#the-style-element">style</a></code> elements, and zero or more <code><a href="semantics.html#meta">meta</a></code> elements.</dd>
609: <dd>When <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-noscript" title='Read about this "scripting is disabled" reference in the full HTML5 spec.'>scripting is disabled</a>, not in a <code><a href="semantics.html#the-head-element-0">head</a></code> element: <a href="content-models.html#transparent">transparent</a>, but there must be no <code><a href="#the-noscript-element">noscript</a></code> element descendants.</dd>
1.11 mike 610: <dd>Otherwise: text that conforms to the requirements given in the prose.</dd>
611: <dt>Content attributes:</dt>
612: <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
613: <dt>DOM interface:</dt>
614: <dd>Uses <code><a href="elements.html#htmlelement">HTMLElement</a></code>.</dd>
1.46 mike 615: </dl><p>The <code><a href="#the-noscript-element">noscript</a></code> element <a class="full-spec-link" href="http://dev.w3.org/html5/spec/rendering.html#represents" title='Read about this "represents" reference in the full HTML5 spec.'>represents</a> nothing
616: if <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-script" title='Read about this "scripting is enabled" reference in the full HTML5 spec.'>scripting is enabled</a>, and
617: <a class="full-spec-link" href="http://dev.w3.org/html5/spec/rendering.html#represents" title='Read about this "represents" reference in the full HTML5 spec.'>represents</a> its children if <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-noscript" title='Read about this "scripting is disabled" reference in the full HTML5 spec.'>scripting is disabled</a>. It is used
1.11 mike 618: to present different markup to user agents that support scripting
619: and those that don't support scripting, by affecting how the
1.46 mike 620: document is parsed.<p>When used in <a href="dom.html#html-documents">HTML documents</a>, the allowed content
621: model is as follows:<dl><dt>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element, if <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-noscript" title='Read about this "scripting is disabled" reference in the full HTML5 spec.'>scripting is disabled</a> for the
1.11 mike 622: <code><a href="#the-noscript-element">noscript</a></code> element</dt>
623:
624: <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only
625: <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>, and <code><a href="semantics.html#meta">meta</a></code>
1.46 mike 626: elements.</dd>
1.11 mike 627:
1.46 mike 628: <dt>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element, if <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-script" title='Read about this "scripting is enabled" reference in the full HTML5 spec.'>scripting is enabled</a> for the
1.11 mike 629: <code><a href="#the-noscript-element">noscript</a></code> element</dt>
630:
631: <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
1.46 mike 632: except that invoking the <a class="full-spec-link" href="http://dev.w3.org/html5/spec/the-end.html#html-fragment-parsing-algorithm" title='Read about this "HTML fragment parsing algorithm" reference in the full HTML5 spec.'>HTML fragment parsing
1.12 mike 633: algorithm</a> <!-- (which disables <script type="text/javascript"> execution) --> with
1.11 mike 634: the <code><a href="#the-noscript-element">noscript</a></code> element as the <var title="">context</var> element and the text contents as the <var title="">input</var> must result in a list of nodes that consists
635: only of <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>, and
636: <code><a href="semantics.html#meta">meta</a></code> elements that would be conforming if they were
1.46 mike 637: children of the <code><a href="#the-noscript-element">noscript</a></code> element, and no <a class="full-spec-link" href="http://dev.w3.org/html5/spec/parsing.html#parse-error" title='Read about this "parse errors" reference in the full HTML5 spec.'>parse errors</a>.</dd>
1.11 mike 638:
1.46 mike 639: <dt>Outside of <code><a href="semantics.html#the-head-element-0">head</a></code> elements, if <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-noscript" title='Read about this "scripting is disabled" reference in the full HTML5 spec.'>scripting is disabled</a> for the
1.11 mike 640: <code><a href="#the-noscript-element">noscript</a></code> element</dt>
641:
642: <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element's content model is
643: <a href="content-models.html#transparent">transparent</a>, with the additional restriction that a
644: <code><a href="#the-noscript-element">noscript</a></code> element must not have a <code><a href="#the-noscript-element">noscript</a></code>
645: element as an ancestor (that is, <code><a href="#the-noscript-element">noscript</a></code> can't be
1.46 mike 646: nested).</dd>
1.11 mike 647:
1.46 mike 648: <dt>Outside of <code><a href="semantics.html#the-head-element-0">head</a></code> elements, if <a class="full-spec-link" href="http://dev.w3.org/html5/spec/webappapis.html#concept-n-script" title='Read about this "scripting is enabled" reference in the full HTML5 spec.'>scripting is enabled</a> for the
1.11 mike 649: <code><a href="#the-noscript-element">noscript</a></code> element</dt>
650:
651: <dd>
652:
653: <p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
654: except that the text must be such that running the following
655: algorithm results in a conforming document with no
656: <code><a href="#the-noscript-element">noscript</a></code> elements and no <code><a href="#script">script</a></code>
657: elements, and such that no step in the algorithm causes an
1.46 mike 658: <a class="full-spec-link" href="http://dev.w3.org/html5/spec/parsing.html#html-parser" title='Read about this "HTML parser" reference in the full HTML5 spec.'>HTML parser</a> to flag a <a class="full-spec-link" href="http://dev.w3.org/html5/spec/parsing.html#parse-error" title='Read about this "parse error" reference in the full HTML5 spec.'>parse error</a>:</p>
1.11 mike 659:
660: <ol><li>Remove every <code><a href="#script">script</a></code> element from the
661: document.</li>
662:
663: <li>Make a list of every <code><a href="#the-noscript-element">noscript</a></code> element in the
664: document. For every <code><a href="#the-noscript-element">noscript</a></code> element in that list,
665: perform the following steps:
666:
667: <ol><li>Let the <var title="">parent element</var> be the parent
668: element of the <code><a href="#the-noscript-element">noscript</a></code> element.</li>
669:
670: <li>Take all the children of the <var title="">parent element</var>
671: that come before the <code><a href="#the-noscript-element">noscript</a></code> element, and call these
672: elements <var title="">the before children</var>.</li>
673:
674: <li>Take all the children of the <var title="">parent element</var>
675: that come <em>after</em> the <code><a href="#the-noscript-element">noscript</a></code> element, and
676: call these elements <var title="">the after children</var>.</li>
677:
678: <li>Let <var title="">s</var> be the concatenation of all the
679: <a href="infrastructure.html#text-node">text node</a> children of the <code><a href="#the-noscript-element">noscript</a></code>
680: element.</li>
681:
682: <li>Set the <code title="dom-innerHTML"><a href="apis-in-html-documents.html#dom-innerhtml">innerHTML</a></code>
683: attribute of the <var title="">parent element</var> to the value
684: of <var title="">s</var>. (This, as a side-effect, causes the
685: <code><a href="#the-noscript-element">noscript</a></code> element to be removed from the
686: document.)</li>
687:
688: <li>Insert <var title="">the before children</var> at the start of
689: the <var title="">parent element</var>, preserving their original
690: relative order.</li>
691:
692: <li>Insert <var title="">the after children</var> at the end of the
693: <var title="">parent element</var>, preserving their original
694: relative order.</li>
695:
696: </ol></li>
697:
698: </ol></dd>
699:
700: </dl><p class="note">All these contortions are required because, for
701: historical reasons, the <code><a href="#the-noscript-element">noscript</a></code> element is handled
1.46 mike 702: differently by the <a class="full-spec-link" href="http://dev.w3.org/html5/spec/parsing.html#html-parser" title='Read about this "HTML parser" reference in the full HTML5 spec.'>HTML parser</a> based on whether <a class="full-spec-link" href="http://dev.w3.org/html5/spec/parsing.html#scripting-flag" title='Read about this "scripting was enabled or not" reference in the full HTML5 spec.'>scripting was enabled or not</a> when the
703: parser was invoked.<p>The <code><a href="#the-noscript-element">noscript</a></code> element must not be used in <a href="dom.html#xml-documents">XML
704: documents</a>.<p class="note"><strong>The <code><a href="#the-noscript-element">noscript</a></code> element is only
1.11 mike 705: effective in <a href="syntax.html#syntax">the HTML syntax</a>, it has no effect in
1.46 mike 706: <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML syntax</a>.</strong><div class="example">
1.11 mike 707:
708: <p>In the following example, a <code><a href="#the-noscript-element">noscript</a></code> element is
709: used to provide fallback for a script.</p>
710:
711: <pre><form action="calcSquare.php">
712: <p>
713: <label for=x>Number</label>:
714: <input id="x" name="x" type="number">
715: </p>
716: <script>
717: var x = document.getElementById('x');
718: var output = document.createElement('p');
719: output.textContent = 'Type a number; it will be squared right then!';
720: x.form.appendChild(output);
721: x.form.onsubmit = function () { return false; }
722: x.oninput = function () {
723: var v = x.valueAsNumber;
724: output.textContent = v + ' squared is ' + v * v;
725: };
726: </script>
727: <noscript>
728: <input type=submit value="Calculate Square">
729: </noscript>
730: </form></pre>
731:
732: <p>When script is disabled, a button appears to do the calculation
733: on the server side. When script is enabled, the value is computed
734: on-the-fly instead.</p>
735:
736: <p>The <code><a href="#the-noscript-element">noscript</a></code> element is a blunt
737: instrument. Sometimes, scripts might be enabled, but for some
738: reason the page's script might fail. For this reason, it's
739: generally better to avoid using <code><a href="#the-noscript-element">noscript</a></code>, and to
740: instead design the script to change the page from being a
741: scriptless page to a scripted page on the fly, as in the next
742: example:</p>
743:
744: <pre><form action="calcSquare.php">
745: <p>
746: <label for=x>Number</label>:
747: <input id="x" name="x" type="number">
748: </p>
749: <strong><input id="submit" type=submit value="Calculate Square"></strong>
750: <script>
751: var x = document.getElementById('x');
752: var output = document.createElement('p');
753: output.textContent = 'Type a number; it will be squared right then!';
754: x.form.appendChild(output);
755: x.form.onsubmit = function () { return false; }
756: x.oninput = function () {
757: var v = x.valueAsNumber;
758: output.textContent = v + ' squared is ' + v * v;
759: };
760: <strong> var submit = document.getElementById('submit');
761: submit.parentNode.removeChild(submit);</strong>
762: </script>
763: </form></pre>
764:
765: <p>The above technique is also useful in XHTML, since
1.26 mike 766: <code><a href="#the-noscript-element">noscript</a></code> is not supported in <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML
1.11 mike 767: syntax</a>.</p>
768:
1.46 mike 769: </div>
Webmaster