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