Annotation of html5/spec/scripting-1.html, revision 1.31

1.1       mike        1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
                      2: <!DOCTYPE html>
                      3: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie" class="split chapter"><head><title>4.3 Scripting &#8212; HTML5 </title><style type="text/css">
1.31    ! mike        4: body, p, div, h1, h2, h3, h4, h5, h6, a, code, strong { color: #999999 ! important; background: white ! important; }
1.1       mike        5:    pre { margin-left: 2em; white-space: pre-wrap; }
                      6:    h2 { margin: 3em 0 1em 0; }
                      7:    h3 { margin: 2.5em 0 1em 0; }
                      8:    h4 { margin: 2.5em 0 0.75em 0; }
                      9:    h5, h6 { margin: 2.5em 0 1em; }
                     10:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                     11:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                     12:    p { margin: 1em 0; }
                     13:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     14:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     15:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     16:    dt + dt { margin-top: 0; }
                     17:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     18:    dd p { margin-top: 0; }
                     19:    dd dl + p { margin-top: 1em; }
                     20:    dd table + p { margin-top: 1em; }
                     21:    p + * > li, dd li { margin: 1em 0; }
                     22:    dt, dfn { font-weight: bold; font-style: normal; }
                     23:    dt dfn { font-style: italic; }
                     24:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     25:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     26:    pre em { font-weight: bolder; font-style: normal; }
                     27:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     28:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     29:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
                     30:    table thead, table tbody { border-bottom: solid; }
                     31:    table tbody th:first-child { border-left: solid; }
                     32:    table tbody th { text-align: left; }
                     33:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     34:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     35: 
                     36:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     37:    .matrix, .matrix td { border: none; text-align: right; }
                     38:    .matrix { margin-left: 2em; }
                     39:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     40:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     41:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                     42: 
                     43:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     44:    img.extra { float: right; }
                     45:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     46:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     47:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     48:    pre.css:first-line { color: #AAAA50; }
                     49:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
                     50:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     51:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     52:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     53:    dl.domintro dd p { margin: 0.5em 0; }
                     54:    dl.switch { padding-left: 2em; }
                     55:    dl.switch > dt { text-indent: -1.5em; }
                     56:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     57:    dl.triple { padding: 0 0 0 1em; }
                     58:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     59:    dl.triple dt:after { content: ':'; }
                     60:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     61:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     62:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     63:    a .diff-new { border-bottom: 1px blue solid; }
                     64: 
                     65:    h2 { page-break-before: always; }
                     66:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     67:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     68: 
1.29      mike       69:    p  > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]),
                     70:    li > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]), { border-bottom: solid #9999CC; }
1.1       mike       71: 
                     72:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     73:    div.head p { margin: 0; }
                     74:    div.head h1 { margin: 0; }
                     75:    div.head .logo { float: right; margin: 0 1em; }
                     76:    div.head .logo img { border: none } /* remove border from top image */
                     77:    div.head dl { margin: 1em 0; }
                     78:    div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
                     79: 
                     80:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     81:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     82:    body > .toc > li > * { margin-bottom: 0.5em; }
                     83:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     84:    .toc, .toc li { list-style: none; }
                     85: 
                     86:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     87:    .brief li { margin: 0; padding: 0; }
                     88:    .brief li p { margin: 0; padding: 0; }
                     89: 
                     90:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     91:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     92:    .category-list li { display: inline; }
                     93:    .category-list li:not(:last-child)::after { content: ', '; }
                     94:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     95:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     96: 
                     97:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     98:    .XXX > :first-child { margin-top: 0; }
                     99:    p .XXX { line-height: 3em; }
                    100:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                    101:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                    102:    .annotation :link, .annotation :visited { color: inherit; }
                    103:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    104:    .annotation span { border: none ! important; }
                    105:    .note { color: green; background: transparent; font-family: sans-serif; }
                    106:    .warning { color: red; background: transparent; }
                    107:    .note, .warning { font-weight: bolder; font-style: italic; }
                    108:    p.note, div.note { padding: 0.5em 2em; }
                    109:    span.note { padding: 0 2em; }
                    110:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    111:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    112:    .warning:before { font-style: normal; }
                    113:    p.note:before { content: 'Note: '; }
                    114:    p.warning:before { content: '\26A0 Warning! '; }
                    115: 
                    116:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    117:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    118:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
1.9       mike      119:    .bookkeeping dt { margin: 0.5em 2em 0; }
                    120:    .bookkeeping dd { margin: 0 3em 0.5em; }
1.1       mike      121: 
                    122:    h4 { position: relative; z-index: 3; }
                    123:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    124:    .element {
                    125:      background: #EEEEFF;
                    126:      color: black;
                    127:      margin: 0 0 1em 0.15em;
                    128:      padding: 0 1em 0.25em 0.75em;
                    129:      border-left: solid #9999FF 0.25em;
                    130:      position: relative;
                    131:      z-index: 1;
                    132:    }
                    133:    .element:before {
                    134:      position: absolute;
                    135:      z-index: 2;
                    136:      top: 0;
                    137:      left: -1.15em;
                    138:      height: 2em;
                    139:      width: 0.9em;
                    140:      background: #EEEEFF;
                    141:      content: ' ';
                    142:      border-style: none none solid solid;
                    143:      border-color: #9999FF;
                    144:      border-width: 0.25em;
                    145:    }
                    146: 
                    147:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    148:    td > .example:only-child { margin: 0 0 0 0.1em; }
                    149: 
                    150:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    151:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    152:    ul.domTree li li { list-style: none; }
                    153:    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; }
                    154:    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; }
                    155:    ul.domTree span { font-style: italic; font-family: serif; }
                    156:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    157:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    158:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    159:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    160:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    161:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    162:    ul.domTree .t10 code { color: teal; }
                    163: 
                    164:    body.dfnEnabled dfn { cursor: pointer; }
                    165:    .dfnPanel {
                    166:      display: inline;
                    167:      position: absolute;
                    168:      z-index: 10;
                    169:      height: auto;
                    170:      width: auto;
                    171:      padding: 0.5em 0.75em;
                    172:      font: small sans-serif, Droid Sans Fallback;
                    173:      background: #DDDDDD;
                    174:      color: black;
                    175:      border: outset 0.2em;
                    176:    }
                    177:    .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
                    178:    .dfnPanel :link, .dfnPanel :visited { color: black; }
                    179:    .dfnPanel p { font-weight: bolder; }
                    180:    .dfnPanel * + p { margin-top: 0.25em; }
                    181:    .dfnPanel li { list-style-position: inside; }
                    182: 
                    183:    #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
                    184:    #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
                    185:    #configUI p label { display: block; }
                    186:    #configUI #updateUI, #configUI .loginUI { text-align: center; }
                    187:    #configUI input[type=button] { display: block; margin: auto; }
1.8       mike      188: 
1.28      mike      189:    fieldset { margin: 1em; }
                    190:    fieldset > legend * + { margin-top: 0; }
                    191:    fieldset > :last-child { margin-bottom: 0; }
                    192: 
1.1       mike      193:   </style><style type="text/css">
                    194: 
                    195:    .applies thead th > * { display: block; }
                    196:    .applies thead code { display: block; }
                    197:    .applies tbody th { whitespace: nowrap; }
                    198:    .applies td { text-align: center; }
                    199:    .applies .yes { background: yellow; }
                    200: 
1.10      mike      201:    .matrix, .matrix td { border: hidden; text-align: right; }
1.1       mike      202:    .matrix { margin-left: 2em; }
                    203: 
                    204:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    205:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    206:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    207: 
1.17      mike      208:    td.eg { border-width: thin; text-align: center; }
                    209: 
1.1       mike      210:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    211:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    212:    #table-example-1 caption { padding-bottom: 0.5em; }
                    213:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    214:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    215:    #table-example-1 th { font-weight: normal; }
                    216:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    217:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    218:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    219:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    220:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    221:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    222:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    223:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    224:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    225:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    226: 
                    227:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    228:    .apple-table-examples * { font-family: "Times", serif; }
                    229:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    230:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    231:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    232:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    233:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    234:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    235:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
                    236:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    237:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    238:    .apple-table-examples sup { line-height: 0; }
                    239: 
                    240:    .details-example img { vertical-align: top; }
                    241: 
                    242:    #named-character-references-table {
1.24      mike      243:      white-space: nowrap;
1.1       mike      244:      font-size: 0.6em;
1.24      mike      245:      column-width: 30em;
1.1       mike      246:      column-gap: 1em;
1.24      mike      247:      -moz-column-width: 30em;
1.1       mike      248:      -moz-column-gap: 1em;
1.24      mike      249:      -webkit-column-width: 30em;
1.1       mike      250:      -webkit-column-gap: 1em;
                    251:    }
1.24      mike      252:    #named-character-references-table > table > tbody > tr > td:first-child + td,
1.1       mike      253:    #named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
                    254:    #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; }
1.24      mike      255:    #named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
1.1       mike      256: 
1.2       mike      257:    .glyph.control { color: red; }
                    258: 
1.4       mike      259:    @font-face {
                    260:      font-family: 'Essays1743';
                    261:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
                    262:    }
                    263:    @font-face {
                    264:      font-family: 'Essays1743';
                    265:      font-weight: bold;
                    266:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
                    267:    }
                    268:    @font-face {
                    269:      font-family: 'Essays1743';
                    270:      font-style: italic;
                    271:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
                    272:    }
                    273:    @font-face {
                    274:      font-family: 'Essays1743';
                    275:      font-style: italic;
                    276:      font-weight: bold;
                    277:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
                    278:    }
                    279: 
1.1       mike      280:   </style><style type="text/css">
                    281:    .domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
                    282:   </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">
                    283:    function getCookie(name) {
                    284:      var params = location.search.substr(1).split("&");
                    285:      for (var index = 0; index < params.length; index++) {
                    286:        if (params[index] == name)
                    287:          return "1";
                    288:        var data = params[index].split("=");
                    289:        if (data[0] == name)
                    290:          return unescape(data[1]);
                    291:      }
                    292:      var cookies = document.cookie.split("; ");
                    293:      for (var index = 0; index < cookies.length; index++) {
                    294:        var data = cookies[index].split("=");
                    295:        if (data[0] == name)
                    296:          return unescape(data[1]);
                    297:      }
                    298:      return null;
                    299:    }
                    300:    function load(script) {
                    301:      var e = document.createElement('script');
1.30      mike      302:      e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
1.1       mike      303:      document.body.appendChild(e);
                    304:    }
                    305:    function init() {
                    306:      if (location.search == '?slow-browser')
                    307:        return;
                    308:      var configUI = document.createElement('div');
                    309:      configUI.id = 'configUI';
                    310:      document.body.appendChild(configUI);
                    311:      // load('reviewer.js'); // would need cross-site XHR
                    312:      if (document.getElementById('head'))
                    313:        load('toc.js');
                    314:      load('styler.js');
                    315:      // load('updater.js'); // would need cross-site XHR
                    316:      load('dfn.js'); // doesn't support split-out specs, but, oh well.
                    317:      // load('status.js'); // would need cross-site XHR
                    318:      if (getCookie('profile') == '1')
                    319:        document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
                    320:      fixBrokenLink();
                    321:    }
1.30      mike      322:   </script><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css">
1.1       mike      323:   <script src="link-fixup.js"></script>
                    324:   <link href="semantics.html" title="4 The elements of HTML" rel="prev">
                    325:   <link href="spec.html#contents" title="Table of contents" rel="index">
                    326:   <link href="sections.html" title="4.4 Sections" rel="next">
                    327:   </head><body onload="fixBrokenLink(); init()"><div class="head" id="head">
                    328:    <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.3       mike      329: 
1.1       mike      330:    <h1>HTML5</h1>
                    331:    </div><div>
                    332:    <a href="semantics.html">&#8592; 4 The elements of HTML</a> &#8211;
                    333:    <a href="spec.html#contents">Table of contents</a> &#8211;
                    334:    <a href="sections.html">4.4 Sections &#8594;</a>
                    335:   <ol class="toc"><li><ol><li><a href="scripting-1.html#scripting-1"><span class="secno">4.3 </span>Scripting</a>
                    336:     <ol><li><a href="scripting-1.html#script"><span class="secno">4.3.1 </span>The <code>script</code> element</a>
                    337:       <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"><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"><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"><span class="secno">4.3.2 </span>The <code>noscript</code> element</a></li></ol></li></ol></li></ol></div>
                    338: 
1.15      mike      339:   <h3 id="scripting-1"><span class="secno">4.3 </span>Scripting</h3><p>Scripts allow authors to add interactivity to their documents.</p><p>Authors are encouraged to use declarative alternatives to
1.1       mike      340:   scripting where possible, as declarative mechanisms are often more
                    341:   maintainable, and many users disable scripting.</p><div class="example">
                    342:    <p>For example, instead of using script to show or hide a section
                    343:    to show more details, the <code><a href="interactive-elements.html#the-details-element">details</a></code> element could be
                    344:    used.</p>
                    345:   </div><p>Authors are also encouraged to make their applications degrade
                    346:   gracefully in the absence of scripting support.</p><div class="example">
                    347:    <p>For example, if an author provides a link in a table header to
                    348:    dynamically resort the table, the link could also be made to
                    349:    function without scripts by requesting the sorted table from the
                    350:    server.</p>
1.15      mike      351:   </div><h4 id="script"><span class="secno">4.3.1 </span>The <dfn><code>script</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
1.1       mike      352:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                    353:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                    354:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
1.16      mike      355:    <dt>Contexts in which this element can be used:</dt>
1.1       mike      356:    <dd>Where <a href="content-models.html#metadata-content">metadata content</a> is expected.</dd>
                    357:    <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected.</dd>
                    358:    <dt>Content model:</dt>
                    359:    <dd>If there is no <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    360:    attribute, depends on the value of the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, but must match
                    361:    <a href="#restrictions-for-contents-of-script-elements">script content restrictions</a>.</dd>
                    362:    <dd>If there <em>is</em> a <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    363:    attribute, the element must be either empty or contain only
                    364:    <a href="#inline-documentation-for-external-scripts">script documentation</a> that also matches <a href="#restrictions-for-contents-of-script-elements">script
                    365:    content restrictions</a>.</dd>
                    366:    <dt>Content attributes:</dt>
                    367:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
                    368:    <dd><code title="attr-script-src"><a href="#attr-script-src">src</a></code></dd>
                    369:    <dd><code title="attr-script-async"><a href="#attr-script-async">async</a></code></dd>
                    370:    <dd><code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code></dd>
                    371:    <dd><code title="attr-script-type"><a href="#attr-script-type">type</a></code></dd>
                    372:    <dd><code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code></dd>
                    373:    <dt>DOM interface:</dt>
                    374:    <dd>
                    375: <pre class="idl">interface <dfn id="htmlscriptelement">HTMLScriptElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
                    376:            attribute DOMString <a href="#dom-script-src" title="dom-script-src">src</a>;
                    377:            attribute boolean <a href="#dom-script-async" title="dom-script-async">async</a>;
                    378:            attribute boolean <a href="#dom-script-defer" title="dom-script-defer">defer</a>;
                    379:            attribute DOMString <a href="#dom-script-type" title="dom-script-type">type</a>;
                    380:            attribute DOMString <a href="#dom-script-charset" title="dom-script-charset">charset</a>;
                    381:            attribute DOMString <a href="#dom-script-text" title="dom-script-text">text</a>;
                    382: };</pre>
                    383:    </dd>
                    384:   </dl><p>The <code><a href="#script">script</a></code> element allows authors to include dynamic
                    385:   script and data blocks in their documents. The element does not
                    386:   <a href="rendering.html#represents" title="represents">represent</a> content for the user.</p><p>When used to include dynamic scripts, the scripts may either be
                    387:   embedded inline or may be imported from an external file using the
                    388:   <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute. If the language
                    389:   is not that described by "<code title="">text/javascript</code>",
                    390:   then the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute must
                    391:   be present, as described below.</p><p>When used to include data blocks (as opposed to scripts), the
                    392:   data must be embedded inline, the format of the data must be given
                    393:   using the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, and
                    394:   the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute must not be
                    395:   specified.</p><p>The <dfn id="attr-script-type" title="attr-script-type"><code>type</code></dfn>
                    396:   attribute gives the language of the script or format of the data. If
                    397:   the attribute is present, its value must be a <a href="infrastructure.html#valid-mime-type">valid MIME
                    398:   type</a>. The <code title="">charset</code> parameter must not be
                    399:   specified. The default, which is used if the attribute is absent,
                    400:   is "<code title="">text/javascript</code>".</p><p>The <dfn id="attr-script-src" title="attr-script-src"><code>src</code></dfn>
                    401:   attribute, if specified, gives the address of the external script
                    402:   resource to use. The value of the attribute must be a <a href="urls.html#valid-non-empty-url-potentially-surrounded-by-spaces">valid
                    403:   non-empty URL potentially surrounded by spaces</a> identifying a
                    404:   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
                    405:   present, or of the type "<code title="">text/javascript</code>", if
                    406:   the attribute is absent. A resource is a script resource of a given
                    407:   type if that type identifies a scripting language and the resource
                    408:   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>
                    409:   attribute gives the character encoding of the external script
                    410:   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
                    411:   attribute is set, its value must be a valid character encoding name,
                    412:   must be an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the
                    413:   <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> for that encoding, and must match
                    414:   the encoding given in the <code title="">charset</code> parameter of
                    415:   the <a href="fetching-resources.html#content-type" title="Content-Type">Content-Type metadata</a> of the
                    416:   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
                    417:   <dfn id="attr-script-defer" title="attr-script-defer"><code>defer</code></dfn> attributes
                    418:   are <a href="common-microsyntaxes.html#boolean-attribute" title="boolean attribute">boolean attributes</a> that
                    419:   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
                    420:   specified if the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute
                    421:   is not present.</p><p>There are three possible modes that can be selected using these
                    422:   attributes. If the <code title="attr-script-async"><a href="#attr-script-async">async</a></code>
                    423:   attribute is present, then the script will be executed
                    424:   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
                    425:   the <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute is
                    426:   present, then the script is executed when the page has finished
                    427:   parsing. If neither attribute is present, then the script is
                    428:   fetched and executed immediately, before the user agent continues
                    429:   parsing the page.</p><p class="note">The exact processing details for these attributes
                    430:   are, for mostly historical reasons, somewhat non-trivial, involving
                    431:   a number of aspects of HTML. The implementation requirements are
                    432:   therefore by necessity scattered throughout the specification. The
                    433:   algorithms below (in this section) describe the core of this
                    434:   processing, but these algorithms reference and are referenced by the
                    435:   parsing rules for <code><a href="#script">script</a></code> <a href="tokenization.html#scriptTag">start</a>
                    436:   and <a href="tokenization.html#scriptEndTag">end</a> tags in HTML, <a href="tokenization.html#scriptForeignEndTag">in foreign content</a>, and <a href="the-xhtml-syntax.html#scriptTagXML">in XML</a>, the rules for the <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code> method, the
                    437:   handling of <a href="webappapis.html#scripting">scripting</a>, etc.</p><p>The <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute may be
                    438:   specified even if the <code title="attr-script-async"><a href="#attr-script-async">async</a></code>
                    439:   attribute is specified, to cause legacy Web browsers that only
                    440:   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
                    441:   synchronous blocking behavior that is the default.</p><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
                    442:   direct effect; these attribute are only used at specific times
                    443:   described below.</p><!-- by implication, changes to the base URL
                    444:   also have no effect --><div class="impl">
                    445: 
                    446:   <p>A <code><a href="#script">script</a></code> element has several associated pieces of
                    447:   state.</p>
                    448: 
                    449:   <p>The first is a flag indicating whether or not the script block
                    450:   has been <dfn id="already-started">"already started"</dfn>. Initially,
                    451:   <code><a href="#script">script</a></code> elements must have this flag unset (script
                    452:   blocks, when created, are not "already started"). When a
                    453:   <code><a href="#script">script</a></code> element is cloned, the "already started" flag,
                    454:   if set, must be propagated to the clone when it is created.</p>
                    455: 
                    456:   <p>The second is a flag indicating whether the element was
                    457:   <dfn id="parser-inserted">"parser-inserted"</dfn>. Initially, <code><a href="#script">script</a></code>
                    458:   elements must have this flag unset. It is set by the <a href="parsing.html#html-parser">HTML
                    459:   parser</a> and the <a href="the-xhtml-syntax.html#xml-parser">XML parser</a> on <code><a href="#script">script</a></code>
                    460:   elements they insert and affects the processing of those
                    461:   elements.</p>
                    462: 
                    463:   <p>The third is a flag indicating whether or not the script block is
                    464:   <dfn id="ready-to-be-parser-executed">"ready to be parser-executed"</dfn>. Initially,
                    465:   <code><a href="#script">script</a></code> elements must have this flag unset (script
                    466:   blocks, when created, are not "ready to be parser-executed"). This
                    467:   flag is used only for elements that are also
                    468:   <a href="#parser-inserted">"parser-inserted"</a>, to let the parser know when to
                    469:   execute the script.</p>
                    470: 
1.23      mike      471:   <p>The last few pieces of state are <dfn id="the-script-block-s-type"><var>the script block's
                    472:   type</var></dfn>, <dfn id="the-script-block-s-character-encoding"><var>the script block's character
                    473:   encoding</var></dfn>, and <dfn id="the-script-block-s-fallback-character-encoding"><var>the script block's fallback
                    474:   character encoding</var></dfn>. They are determined when the script
                    475:   is run, based on the attributes on the element at that time, and the
                    476:   <code><a href="infrastructure.html#document">Document</a></code> of the <code><a href="#script">script</a></code> element.</p>
1.1       mike      477: 
1.16      mike      478:   <p>When a <code><a href="#script">script</a></code> element that is not marked as being
1.1       mike      479:   <a href="#parser-inserted">"parser-inserted"</a> experiences one of the events listed
                    480:   in the following list, the user agent must synchronously <a href="#running-a-script" title="running a script">run</a> the <code><a href="#script">script</a></code>
                    481:   element:</p>
                    482: 
                    483:   <ul><li>The <code><a href="#script">script</a></code> element gets <a href="infrastructure.html#insert-an-element-into-a-document" title="insert an
                    484:    element into a document">inserted into a document</a>.</li>
                    485: 
                    486:    <li>The <code><a href="#script">script</a></code> element is <a href="infrastructure.html#in-a-document">in a
                    487:    <code>Document</code></a> and its child nodes are changed.</li>
                    488: 
                    489:    <li>The <code><a href="#script">script</a></code> element is <a href="infrastructure.html#in-a-document">in a
                    490:    <code>Document</code></a> and has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute set where previously
                    491:    the element had no such attribute.</li>
                    492: 
                    493:   </ul><p><dfn id="running-a-script" title="running a script">Running a script</dfn>: When a
                    494:   <code><a href="#script">script</a></code> element is to be run, the user agent must act as
                    495:   follows:</p>
                    496: 
1.19      mike      497:   <ol><li>
1.16      mike      498: 
1.19      mike      499:     <p>If the <code><a href="#script">script</a></code> element is marked as having
                    500:     <a href="#already-started">"already started"</a>, then the user agent must abort
                    501:     these steps at this point. The script is not executed.</p>
1.16      mike      502: 
                    503:    </li>
                    504: 
1.18      mike      505:    <li>
                    506: 
                    507:     <p>If the element has its <a href="#parser-inserted">"parser-inserted"</a> flag set,
                    508:     then set <var title="">was-parser-inserted</var> to true and unset
                    509:     the element's <a href="#parser-inserted">"parser-inserted"</a> flag. Otherwise, set
                    510:     <var title="">was-parser-inserted</var> to false.</p>
                    511: 
                    512:     <p class="note">This is done so that if parser-inserted
                    513:     <code><a href="#script">script</a></code> elements fail to run when the parser tries to
                    514:     run them, e.g. because they are empty or specify an unsupported
                    515:     scripting language, another script can later mutate them and cause
                    516:     them to run again.</p>
                    517: 
                    518:     <!-- q.v. http://hsivonen.iki.fi/test/moz/script-setting-src-on-parser-inserted-script.html -->
                    519: 
                    520:    </li>
                    521: 
1.16      mike      522:    <li id="script-processing-empty">
                    523: 
                    524:     <p>If the element has no <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
1.18      mike      525:     attribute, and its child nodes, if any, consist only of comment
                    526:     nodes and empty <a href="infrastructure.html#text-node" title="text node">text nodes</a>, then
                    527:     the user agent must abort these steps at this point. The script is
                    528:     not executed.</p>
1.16      mike      529: 
                    530:    </li>
                    531: 
1.25      mike      532:    <li>
                    533: 
                    534:     <p>If the element is not <a href="infrastructure.html#in-a-document">in a <code>Document</code></a>,
                    535:     then the user agent must abort these steps at this point. The
                    536:     script is not executed.</p>
                    537: 
                    538:    </li>
                    539: 
1.16      mike      540:    <li id="script-processing-prepare">
1.1       mike      541: 
                    542:     <p>If either:</p>
                    543: 
                    544:     <ul class="brief"><li>the <code><a href="#script">script</a></code> element has a <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute and its value is
                    545:      the empty string, or</li>
                    546: 
                    547:      <li>the <code><a href="#script">script</a></code> element has no <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute but it has a <code title="attr-script-language"><a href="obsolete.html#attr-script-language">language</a></code> attribute and
                    548:      <em>that</em> attribute's value is the empty string, or</li>
                    549: 
                    550:      <li>the <code><a href="#script">script</a></code> element has neither a <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute nor a <code title="attr-script-language"><a href="obsolete.html#attr-script-language">language</a></code> attribute, then</li>
                    551: 
                    552:     </ul><p>...let <var><a href="#the-script-block-s-type">the script block's type</a></var> for this
                    553:     <code><a href="#script">script</a></code> element be "<code title="">text/javascript</code>".</p>
                    554: 
                    555:     <p>Otherwise, if the <code><a href="#script">script</a></code> element has a <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, let <var><a href="#the-script-block-s-type">the
                    556:     script block's type</a></var> for this <code><a href="#script">script</a></code> element be
                    557:     the value of that attribute with any leading or trailing sequences
                    558:     of <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>
                    559:     removed.</p>
                    560: 
                    561:     <p>Otherwise, the element has a non-empty <code title="attr-script-language"><a href="obsolete.html#attr-script-language">language</a></code> attribute; let
                    562:     <var><a href="#the-script-block-s-type">the script block's type</a></var> for this <code><a href="#script">script</a></code>
                    563:     element be the concatenation of the string "<code title="">text/</code>" followed by the value of the <code title="attr-script-language"><a href="obsolete.html#attr-script-language">language</a></code> attribute.</p> <!--
                    564:     user agents already support, e.g., type="text/javascript1.3", so
                    565:     we don't have to support that separately. -->
                    566: 
                    567:     <p class="note">The <code title="attr-script-language"><a href="obsolete.html#attr-script-language">language</a></code> attribute is never
                    568:     conforming, and is always ignored if there is a <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute present.</p>
                    569: 
                    570:    </li>
                    571: 
1.16      mike      572:    <li>
                    573: 
                    574:     <p>If the user agent does not <a href="#support-the-scripting-language">support the scripting
                    575:     language</a> given by <var><a href="#the-script-block-s-type">the script block's type</a></var> for
                    576:     this <code><a href="#script">script</a></code> element, then the user agent must abort
                    577:     these steps at this point. The script is not executed.</p>
                    578: 
                    579:    </li>
                    580: 
1.18      mike      581:    <li id="script-processing-start">
                    582: 
                    583:     <p>The user agent must set the element's <a href="#already-started">"already
                    584:     started"</a> flag.</p>
                    585: 
                    586:    </li>
                    587: 
                    588:    <li>
                    589: 
                    590:     <p>If <var title="">was-parser-inserted</var> is true, then flag
                    591:     the element as <a href="#parser-inserted">"parser-inserted"</a> again.</p>
                    592: 
                    593:    </li>
                    594: 
1.19      mike      595:    <li id="script-processing-noscript">
                    596: 
                    597:     <p>If <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is
                    598:     disabled</a> for the <code><a href="#script">script</a></code> element, then the user
                    599:     agent must abort these steps at this point. The script is not
                    600:     executed.</p>
                    601: 
                    602:    </li>
                    603: 
1.1       mike      604:    <li id="script-processing-for">
                    605: 
                    606:     <p>If the <code><a href="#script">script</a></code> element has an <code title="attr-script-event"><a href="obsolete.html#attr-script-event">event</a></code> attribute and a <code title="attr-script-for"><a href="obsolete.html#attr-script-for">for</a></code> attribute, then run these
                    607:     substeps:</p>
                    608: 
                    609:     <ol><li><p>Let <var title="">for</var> be the value of the <code title="attr-script-for"><a href="obsolete.html#attr-script-for">for</a></code> attribute.</p></li>
                    610: 
                    611:      <li><p>Let <var title="">event</var> be the value of the <code title="attr-script-event"><a href="obsolete.html#attr-script-event">event</a></code> attribute.</p></li>
                    612: 
                    613:      <li><p><a href="common-microsyntaxes.html#strip-leading-and-trailing-whitespace">Strip leading and trailing whitespace</a> from
                    614:      <var title="">event</var> and <var title="">for</var>.</p></li>
                    615: 
                    616:      <li><p>If <var title="">for</var> is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                    617:      case-insensitive</a> match for the string "<code title="">window</code>", then the user agent must abort these
                    618:      steps at this point. The script is not executed.</p></li>
                    619: 
                    620:      <li><p>If <var title="">event</var> is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                    621:      case-insensitive</a> match for either the string "<code title="">onload</code>" or the string "<code title="">onload()</code>", then the user agent must abort these
                    622:      steps at this point. The script is not executed.</p></li>
                    623: 
                    624:     </ol></li>
                    625: 
1.19      mike      626:    <li id="script-processing-encoding">
                    627: 
                    628:     <p>If the <code><a href="#script">script</a></code> element has a <code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code> attribute, then let
                    629:     <var><a href="#the-script-block-s-character-encoding">the script block's character encoding</a></var> for this
                    630:     <code><a href="#script">script</a></code> element be the encoding given by the <code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code> attribute.</p>
                    631: 
1.23      mike      632:     <p>Otherwise, let <var><a href="#the-script-block-s-fallback-character-encoding">the script block's fallback character
                    633:     encoding</a></var> for this <code><a href="#script">script</a></code> element be the same as
                    634:     <a href="dom.html#document-s-character-encoding" title="document's character encoding">the encoding of the
                    635:     document itself</a>.</p>
                    636: 
                    637:     <p class="note">Only one of these two pieces of state is set.</p>
1.19      mike      638: 
                    639:    </li>
                    640: 
1.1       mike      641:    <li id="script-processing-src-prepare">
                    642: 
                    643:     <p>If the element has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    644:     attribute whose value is not the empty string, then the value of
                    645:     that attribute must be <a href="urls.html#resolve-a-url" title="resolve a url">resolved</a>
                    646:     relative to the element, and if that is successful, the specified
                    647:     resource must then be <a href="fetching-resources.html#fetch" title="fetch">fetched</a>, from the
                    648:     <a href="origin-0.html#origin">origin</a> of the element's <code><a href="infrastructure.html#document">Document</a></code>.</p>
                    649:     <!-- not http-origin privacy sensitive -->
                    650: 
                    651:     <p>If the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute's
                    652:     value is the empty string or if it could not be resolved, then the
                    653:     user agent must <a href="webappapis.html#queue-a-task">queue a task</a> to <a href="webappapis.html#fire-a-simple-event">fire a simple
                    654:     event</a> named <code title="event-error">error</code> at the
                    655:     element, and abort these steps.</p>
                    656: 
                    657:     <p>For historical reasons, if the <a href="urls.html#url">URL</a> is a <a href="webappapis.html#javascript-protocol" title="javascript protocol"><code title="">javascript:</code>
                    658:     URL</a>, then the user agent must not, despite the requirements
                    659:     in the definition of the <a href="fetching-resources.html#fetch" title="fetch">fetching</a>
                    660:     algorithm, actually execute the script in the URL; instead the
                    661:     user agent must act as if it had received an empty HTTP 400
                    662:     response.</p>
                    663: 
                    664:     <p>For performance reasons, user agents may start fetching the
                    665:     script as soon as the attribute is set, instead, in the hope that
                    666:     the element will be inserted into the document. Either way, once
                    667:     the element is <a href="infrastructure.html#insert-an-element-into-a-document" title="insert an element into a
                    668:     document">inserted into the document</a>, the load must have
                    669:     started. If the UA performs such prefetching, but the element is
                    670:     never inserted in the document, or the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is dynamically
                    671:     changed,<!-- or the base URL is dynamically changed,--> then the
                    672:     user agent will not execute the script, and the fetching process
                    673:     will have been effectively wasted.</p>
                    674: 
                    675:    </li>
                    676: 
                    677:    <li>
                    678: 
                    679:     <p>Then, the first of the following options that describes the
                    680:     situation must be followed:</p>
                    681: 
                    682:     <dl class="switch"><dt id="script-processing-defer">If the element has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute, and the element has
                    683:      a <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute, and the
                    684:      element has been flagged as <a href="#parser-inserted">"parser-inserted"</a>, and
                    685:      the element does not have an <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute</dt>
                    686: 
                    687:      <dd>
                    688: 
                    689:       <p>The element must be added to the end of the <dfn id="list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of
                    690:       scripts that will execute when the document has finished
1.20      mike      691:       parsing</dfn> associated with the <code><a href="infrastructure.html#document">Document</a></code> of the
                    692:       parser that created the element.</p>
1.1       mike      693: 
                    694:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    695:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    696:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
                    697:       algorithm</a> has completed must set the element's
                    698:       <a href="#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag. The parser will
                    699:       handle executing the script.</p>
                    700: 
                    701:      </dd>
                    702: 
                    703: 
                    704:      <dt id="script-processing-parser-inserted">If the element has a
                    705:      <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute, and the
                    706:      element has been flagged as <a href="#parser-inserted">"parser-inserted"</a>, and
                    707:      the element does not have an <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute</dt>
                    708: 
                    709:      <dd>
                    710: 
                    711:       <p>The element is the <a href="#pending-parsing-blocking-script">pending parsing-blocking
1.20      mike      712:       script</a> of the <code><a href="infrastructure.html#document">Document</a></code> of the parser that
                    713:       created the element. (There can only be one such script per
                    714:       <code><a href="infrastructure.html#document">Document</a></code> at a time.)</p>
1.1       mike      715: 
                    716:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    717:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    718:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
                    719:       algorithm</a> has completed must set the element's
                    720:       <a href="#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag. The parser will
                    721:       handle executing the script.</p>
                    722: 
                    723:      </dd>
                    724: 
                    725: 
                    726:      <dt id="script-processing-style-delayed">If the element does not
                    727:      have a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute, but
1.21      mike      728:      there is <a href="semantics.html#a-style-sheet-that-is-blocking-scripts">a style sheet that is blocking scripts</a>, and
                    729:      the element has been flagged as
                    730:      <a href="#parser-inserted">"parser-inserted"</a></dt>
1.1       mike      731: 
                    732:      <dd>
                    733: 
                    734:       <p>The element is the <a href="#pending-parsing-blocking-script">pending parsing-blocking
1.20      mike      735:       script</a> of the <code><a href="infrastructure.html#document">Document</a></code> of the parser that
                    736:       created the element. (There can only be one such script per
                    737:       <code><a href="infrastructure.html#document">Document</a></code> at a time.)</p>
1.1       mike      738: 
                    739:       <p>Set the element's <a href="#ready-to-be-parser-executed">"ready to be parser-executed"</a>
                    740:       flag. The parser will handle executing the script.</p>
                    741: 
                    742:      </dd>
                    743: 
                    744: 
                    745:      <dt id="script-processing-src">If the element has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute</dt>
                    746: 
                    747:      <dd>
                    748: 
                    749:       <p>The element must be added to the <dfn id="set-of-scripts-that-will-execute-as-soon-as-possible">set of scripts that
1.20      mike      750:       will execute as soon as possible</dfn> of the
                    751:       <code><a href="infrastructure.html#document">Document</a></code> of the <code><a href="#script">script</a></code> element at the
                    752:       time the <a href="#running-a-script">running a script</a> algorithm started.</p>
1.1       mike      753: 
                    754:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    755:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    756:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
                    757:       algorithm</a> has completed must <a href="#executing-a-script-block" title="executing a
                    758:       script block">execute the script block</a> and then remove
                    759:       the element from the <a href="#set-of-scripts-that-will-execute-as-soon-as-possible">set of scripts that will execute as
                    760:       soon as possible</a>.</p>
                    761: 
                    762:      </dd>
                    763: 
                    764: 
                    765:      <dt id="script-processing-inline">Otherwise</dt>
                    766: 
                    767:      <dd>The user agent must immediately <a href="#executing-a-script-block" title="executing a
                    768:      script block">execute the script block</a>, even if other
                    769:      scripts are already executing.</dd>
                    770: 
                    771:     </dl></li>
                    772: 
                    773:   </ol><!-- similar text in various places --><p>Fetching an external script must <a href="the-end.html#delay-the-load-event">delay the load
                    774:   event</a> of the element's document until the <a href="webappapis.html#concept-task" title="concept-task">task</a> that is <a href="webappapis.html#queue-a-task" title="queue a
                    775:   task">queued</a> by the <a href="webappapis.html#networking-task-source">networking task source</a> once
                    776:   the resource has been <a href="fetching-resources.html#fetch" title="fetch">fetched</a> (defined
                    777:   above) has been run.</p>
                    778: 
1.20      mike      779:   <p>The <dfn id="pending-parsing-blocking-script">pending parsing-blocking script</dfn> of a
                    780:   <code><a href="infrastructure.html#document">Document</a></code> is used by the <code><a href="infrastructure.html#document">Document</a></code>'s
                    781:   parser(s).</p>
1.1       mike      782: 
1.26      mike      783:   <p class="note">If a <code><a href="#script">script</a></code> element that blocks a
                    784:   parser gets moved to another <code><a href="infrastructure.html#document">Document</a></code> before it would
                    785:   normally have stopped blocking that parser, it nonetheless continues
                    786:   blocking that parser until the condition that causes it to be
                    787:   blocking the parser no longer applies (e.g. if the script is a
                    788:   <a href="#pending-parsing-blocking-script">pending parsing-blocking script</a> because there was
                    789:   <a href="semantics.html#a-style-sheet-that-is-blocking-scripts">a style sheet that is blocking scripts</a> when it was
                    790:   parsed, but then the script is moved to another
                    791:   <code><a href="infrastructure.html#document">Document</a></code> before the style sheet loads, the script still
                    792:   blocks the parser until the style sheets are all loaded, at which
                    793:   time the script executes and the parser is unblocked).</p>
                    794: 
                    795:   <!-- also (and this would be worth testing): the way the spec is
                    796:   written, if you do not have a style sheet that is blocking scripts,
                    797:   then you parse a <script src>, then while waiting for the script to
                    798:   load you insert an external style sheet, the script will delay until
                    799:   the sheet is loaded, because there's just a binary "are style sheets
                    800:   blocking scripts" state, things aren't defined in terms of which
                    801:   style sheets are blocking which scripts -->
                    802: 
1.1       mike      803:   <p><dfn id="executing-a-script-block" title="executing a script block">Executing a script
                    804:   block</dfn>: When the steps above require that the script block be
                    805:   executed, the user agent must act as follows:</p>
                    806: 
                    807:   <dl class="switch"><dt>If the load resulted in an error (for example a DNS error, or
                    808:    an HTTP 404 error)</dt>
                    809: 
                    810:    <dd><p>Executing the script block must just consist of <a href="webappapis.html#fire-a-simple-event" title="fire a simple event">firing a simple event</a> named
                    811:    <code title="event-error">error</code> at the element.</p></dd>
                    812: 
                    813:    <dt>If the load was successful</dt>
                    814: 
                    815:    <!-- SCRIPT EXEC -->
                    816:    <dd>
                    817: 
1.27      mike      818:     <p>Executing the script block must consists of running the
                    819:     following steps. For the purposes of these steps, the script is
                    820:     considered to be from an <i>external file</i> if, while the
                    821:     <a href="#running-a-script">running a script</a> algorithm above was running for this
                    822:     script, the <code><a href="#script">script</a></code> element had a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute specified.</p>
                    823: 
1.1       mike      824:     <ol><li>
                    825: 
                    826:       <p>Initialize <dfn id="the-script-block-s-source"><var>the script block's source</var></dfn> as
                    827:       follows:</p>
                    828: 
                    829:       <dl class="switch"><dt>If the script is from an external file and <var><a href="#the-script-block-s-type">the script block's type</a></var> is a text-based language</dt>
                    830: 
                    831:        <dd>
                    832: 
                    833:         <p>The contents of that file, interpreted as string of
                    834:         Unicode characters, are the script source.</p>
                    835: 
1.23      mike      836:         <p>To obtain the string of Unicode characters, the user agent
                    837:         run the following steps:</p>
1.1       mike      838: 
1.23      mike      839:         <ol><li><p>If the resource's <a href="fetching-resources.html#content-type" title="Content-Type">Content
                    840:          Type metadata</a>, if any, specifies a character encoding,
                    841:          and the user agent supports that encoding, then let <var title="">character encoding</var> be that encoding, and jump
                    842:          to the bottom step in this series of steps.</p></li>
                    843: 
                    844:          <li><p>If the algorithm above set <var><a href="#the-script-block-s-character-encoding">the script block's
                    845:          character encoding</a></var>, then let <var title="">character
                    846:          encoding</var> be that encoding, and jump to the bottom step
                    847:          in this series of steps.</p></li>
                    848: 
                    849:          <li><p>For each of the rows in the following table, starting
                    850:          with the first one and going down, if the file has as many or
                    851:          more bytes available than the number of bytes in the first
                    852:          column, and the first bytes of the file match the bytes given
                    853:          in the first column, then set <var title="">character
                    854:          encoding</var> to the encoding given in the cell in the
                    855:          second column of that row, and jump to the bottom step in
                    856:          this series of steps:</p>
                    857: 
                    858:           <!-- this table is present in several forms in this file; keep them in sync -->
                    859:           <table id="table-script-bom"><thead><tr><th>Bytes in Hexadecimal
                    860:              </th><th>Encoding
                    861:            </th></tr></thead><tbody><!-- nobody uses this
                    862:             <tr>
                    863:              <td>00 00 FE FF
                    864:              <td>UTF-32BE
                    865:             <tr>
                    866:              <td>FF FE 00 00
                    867:              <td>UTF-32LE
                    868:   --><tr><td>FE FF
                    869:              </td><td>Big-endian UTF-16
                    870:             </td></tr><tr><td>FF FE
                    871:              </td><td>Little-endian UTF-16
                    872:             </td></tr><tr><td>EF BB BF
                    873:              </td><td>UTF-8
                    874:   <!-- nobody uses this
                    875:             <tr>
                    876:              <td>DD 73 66 73
                    877:              <td>UTF-EBCDIC
                    878:   -->
                    879:           </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                    880:           (BOMs).</p>
                    881: 
                    882:          </li>
                    883: 
                    884:          <li><p>Let <var title="">character encoding</var> be <var><a href="#the-script-block-s-fallback-character-encoding">the
                    885:          script block's fallback character encoding</a></var>.</p></li>
                    886: 
                    887:          <li><p>Convert the file to Unicode using <var>character
                    888:          encoding</var>, following the rules for doing so given by the
                    889:          specification for <var><a href="#the-script-block-s-type">the script block's
                    890:          type</a></var>.</p></li>
                    891: 
                    892:         </ol></dd>
1.1       mike      893: 
                    894:        <dt>If the script is from an external file and <var><a href="#the-script-block-s-type">the script block's type</a></var> is an XML-based language</dt>
                    895: 
                    896:        <dd>
                    897: 
                    898:         <p>The external file is the script source. When it is later
                    899:         executed, it must be interpreted in a manner consistent with
                    900:         the specification defining the language given by <var><a href="#the-script-block-s-type">the
                    901:         script block's type</a></var>.</p>
                    902: 
                    903:        </dd>
                    904: 
                    905:        <dt>If the script is inline and <var><a href="#the-script-block-s-type">the script block's type</a></var> is a text-based language</dt>
                    906: 
                    907:        <dd>
                    908: 
                    909:         <p>The value of the <code title="dom-script-text"><a href="#dom-script-text">text</a></code>
                    910:         IDL attribute at the time the element's <a href="#already-started">"already
                    911:         started"</a> flag was set is the script source.</p>
                    912: 
                    913:        </dd>
                    914: 
                    915:        <dt>If the script is inline and <var><a href="#the-script-block-s-type">the script block's type</a></var> is an XML-based language</dt>
                    916: 
                    917:        <dd>
                    918: 
                    919:         <p>The child nodes of the <code><a href="#script">script</a></code> element at the
                    920:         time the element's <a href="#already-started">"already started"</a> flag was set
                    921:         are the script source.</p>
                    922: 
                    923:        </dd>
                    924: 
                    925:       </dl></li>
                    926: 
                    927:      <li>
                    928: 
1.27      mike      929:       <p>If the script is from an external file, then increment the
                    930:       <a href="apis-in-html-documents.html#ignore-destructive-writes-counter">ignore-destructive-writes counter</a> of the
                    931:       <code><a href="#script">script</a></code> element's <code><a href="infrastructure.html#document">Document</a></code>. Let <var title="">neutralized doc</var> be that
1.7       mike      932:       <code><a href="infrastructure.html#document">Document</a></code>.</p>
                    933: 
                    934:      </li>
                    935: 
                    936:      <li>
                    937: 
1.1       mike      938:       <p><a href="webappapis.html#create-a-script-from-a-node" title="create a script from a node">Create a
                    939:       script</a> from the <code><a href="#script">script</a></code> element node, using
                    940:       <var><a href="#the-script-block-s-source">the script block's source</a></var> and <var><a href="#the-script-block-s-type">the script
                    941:       block's type</a></var>.</p>
                    942: 
                    943:       <p class="note">This is where the script is compiled and
                    944:       actually executed.</p>
                    945: 
                    946:      </li>
                    947: 
                    948:      <li>
                    949: 
1.27      mike      950:       <p>Decrement the <a href="apis-in-html-documents.html#ignore-destructive-writes-counter">ignore-destructive-writes counter</a>
                    951:       of <var title="">neutralized doc</var>, if it was incremented in
                    952:       the earlier step.</p>
1.7       mike      953: 
                    954:      </li>
                    955: 
                    956:      <li>
                    957: 
1.1       mike      958:       <p>If the script is from an external file, <a href="webappapis.html#fire-a-simple-event">fire a simple
                    959:       event</a> named <code title="event-load">load</code> at the
                    960:       <code><a href="#script">script</a></code> element.</p>
                    961: 
                    962:       <p>Otherwise, the script is internal; <a href="webappapis.html#queue-a-task">queue a task</a>
                    963:       to <a href="webappapis.html#fire-a-simple-event">fire a simple event</a> named <code title="event-load">load</code> at the <code><a href="#script">script</a></code>
                    964:       element.</p>
                    965: 
                    966:      </li>
                    967: 
                    968:     </ol></dd>
                    969: 
                    970:   </dl><p>The IDL attributes <dfn id="dom-script-src" title="dom-script-src"><code>src</code></dfn>, <dfn id="dom-script-type" title="dom-script-type"><code>type</code></dfn>, <dfn id="dom-script-charset" title="dom-script-charset"><code>charset</code></dfn>, <dfn id="dom-script-async" title="dom-script-async"><code>async</code></dfn>, and <dfn id="dom-script-defer" title="dom-script-defer"><code>defer</code></dfn>, each must
                    971:   <a href="common-dom-interfaces.html#reflect">reflect</a> the respective content attributes of the same
                    972:   name.</p>
                    973: 
                    974:   </div><dl class="domintro"><dt><var title="">script</var> . <code title="dom-script-text"><a href="#dom-script-text">text</a></code> [ = <var title="">value</var> ]</dt>
                    975: 
                    976:    <dd>
                    977: 
                    978:     <p>Returns the contents of the element, ignoring child nodes that
                    979:     aren't <a href="infrastructure.html#text-node" title="text node">text nodes</a>.</p>
                    980: 
                    981:     <p>Can be set, to replace the element's children with the given
                    982:     value.</p>
                    983: 
                    984:    </dd>
                    985: 
                    986:   </dl><div class="impl">
                    987: 
                    988:   <p>The IDL attribute <dfn id="dom-script-text" title="dom-script-text"><code>text</code></dfn> must return a
                    989:   concatenation of the contents of all the <a href="infrastructure.html#text-node" title="text
                    990:   node">text nodes</a> that are direct children of the
                    991:   <code><a href="#script">script</a></code> element (ignoring any other nodes such as
                    992:   comments or elements), in tree order. On setting, it must act the
                    993:   same way as the <code><a href="infrastructure.html#textcontent">textContent</a></code> IDL attribute.</p>
                    994: 
                    995:   </div><p class="note">When inserted using the <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code> method,
                    996:   <code><a href="#script">script</a></code> elements execute (typically synchronously), but
                    997:   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
                    998:   execute at all.</p><div class="example">
                    999: 
                   1000:    <p>In this example, two <code><a href="#script">script</a></code> elements are used. One
                   1001:    embeds an external script, and the other includes some data.</p>
                   1002: 
                   1003:    <pre>&lt;script src="game-engine.js"&gt;&lt;/script&gt;
                   1004: &lt;script type="text/x-game-map"&gt;
                   1005: ........U.........e
                   1006: o............A....e
                   1007: .....A.....AAA....e
                   1008: .A..AAA...AAAAA...e
                   1009: &lt;/script&gt;</pre>
                   1010: 
                   1011:    <p>The data in this case might be used by the script to generate
                   1012:    the map of a video game. The data doesn't have to be used that way,
                   1013:    though; maybe the map data is actually embedded in other parts of
                   1014:    the page's markup, and the data block here is just used by the
                   1015:    site's search engine to help users who are looking for particular
                   1016:    features in their game maps.</p>
                   1017: 
                   1018:   </div><div class="example">
                   1019: 
                   1020:    <p>The following sample shows how a script element can be used to
                   1021:    define a function that is then used by other parts of the
                   1022:    document. It also shows how a <code><a href="#script">script</a></code> element can be
                   1023:    used to invoke script while the document is being parsed, in this
                   1024:    case to initialize the form's output.</p>
                   1025: 
                   1026:    <pre>&lt;script&gt;
                   1027:  function calculate(form) {
                   1028:    var price = 52000;
                   1029:    if (form.elements.brakes.checked)
                   1030:      price += 1000;
                   1031:    if (form.elements.radio.checked)
                   1032:      price += 2500;
                   1033:    if (form.elements.turbo.checked)
                   1034:      price += 5000;
                   1035:    if (form.elements.sticker.checked)
                   1036:      price += 250;
                   1037:    form.elements.result.value = price;
                   1038:  }
                   1039: &lt;/script&gt;
                   1040: &lt;form name="pricecalc" onsubmit="return false"&gt;
                   1041:  &lt;fieldset&gt;
                   1042:   &lt;legend&gt;Work out the price of your car&lt;/legend&gt;
                   1043:   &lt;p&gt;Base cost: &#163;52000.&lt;/p&gt;
                   1044:   &lt;p&gt;Select additional options:&lt;/p&gt;
                   1045:   &lt;ul&gt;
                   1046:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=brakes&gt; Ceramic brakes (&#163;1000)&lt;/label&gt;&lt;/li&gt;
                   1047:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=radio&gt; Satellite radio (&#163;2500)&lt;/label&gt;&lt;/li&gt;
                   1048:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=turbo&gt; Turbo charger (&#163;5000)&lt;/label&gt;&lt;/li&gt;
                   1049:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=sticker&gt; "XZ" sticker (&#163;250)&lt;/label&gt;&lt;/li&gt;
                   1050:   &lt;/ul&gt;
                   1051:   &lt;p&gt;Total: &#163;&lt;output name=result onformchange="calculate(form)"&gt;&lt;/output&gt;&lt;/p&gt;
                   1052:  &lt;/fieldset&gt;
                   1053:  &lt;script&gt;
                   1054:   document.forms.pricecalc.dispatchFormChange();
                   1055:  &lt;/script&gt;
                   1056: &lt;/form&gt;</pre>
                   1057: 
1.15      mike     1058:   </div><h5 id="scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</h5><div class="impl">
1.1       mike     1059: 
                   1060:   <p>A user agent is said to <dfn id="support-the-scripting-language">support the scripting language</dfn>
                   1061:   if <var><a href="#the-script-block-s-type">the script block's type</a></var> is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   1062:   case-insensitive</a> match for the <a href="infrastructure.html#mime-type">MIME type</a> string
                   1063:   of a scripting language that the user agent implements.</p>
                   1064: 
                   1065:   </div><p>The following lists some <a href="infrastructure.html#mime-type">MIME type</a> strings and the
                   1066:   languages to which they refer:</p><dl><dt>"<code>application/ecmascript</code>"</dt>
                   1067:    <dt>"<code>application/javascript</code>"</dt>
                   1068:    <dt>"<code>application/x-ecmascript</code>"</dt>
                   1069:    <dt>"<code>application/x-javascript</code>"</dt>
                   1070:    <dt>"<code>text/ecmascript</code>"</dt>
                   1071:    <dt>"<code>text/javascript</code>"</dt>
                   1072:    <dt>"<code>text/javascript1.0</code>"</dt>
                   1073:    <dt>"<code>text/javascript1.1</code>"</dt>
                   1074:    <dt>"<code>text/javascript1.2</code>"</dt>
                   1075:    <dt>"<code>text/javascript1.3</code>"</dt>
                   1076:    <dt>"<code>text/javascript1.4</code>"</dt>
                   1077:    <dt>"<code>text/javascript1.5</code>"</dt>
                   1078:    <dt>"<code>text/jscript</code>"</dt>
                   1079:    <dt>"<code>text/livescript</code>"</dt>
                   1080:    <dt>"<code>text/x-ecmascript</code>"</dt>
                   1081:    <dt>"<code>text/x-javascript</code>"</dt>
                   1082:    <dd>JavaScript. <a href="references.html#refsECMA262">[ECMA262]</a></dd>
                   1083: 
                   1084:    <dt>"<code>text/javascript;e4x=1</code>"</dt>
                   1085:    <dd>JavaScript with ECMAScript for XML. <a href="references.html#refsECMA357">[ECMA357]</a></dd>
                   1086: 
                   1087:   </dl><div class="impl">
                   1088: 
                   1089:   <p>User agents may support other <a href="infrastructure.html#mime-type" title="MIME type">MIME
                   1090:   types</a> and other languages.</p>
                   1091: 
                   1092:   <!-- this paragraph is also present in the <style type="text/css"> section -->
                   1093:   <p>When examining types to determine if they support the language,
                   1094:   user agents must not ignore unknown MIME parameters &#8212; types
                   1095:   with unknown parameters must be assumed to be unsupported. The <code title="">charset</code> parameter must be treated as an unknown
                   1096:   parameter for the purpose of comparing <a href="infrastructure.html#mime-type" title="MIME type">MIME
                   1097:   types</a> here.</p>
                   1098: 
1.15      mike     1099:   </div><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>The <code><a href="infrastructure.html#textcontent">textContent</a></code> of a <code><a href="#script">script</a></code> element must match the
1.1       mike     1100:   <code title="">script</code> production in the following ABNF, the
                   1101:   character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a></p><pre>script        = data1 *( escape [ script-start data3 ] "--&gt;" data1 ) [ escape ]
                   1102: escape        = "&lt;!--" data2 *( script-start data3 script-end data2 )
                   1103: 
                   1104: data1         = &lt;any string that doesn't contain a substring that matches not-data1&gt;
                   1105: not-data1     = <!-- script-end / -->"&lt;!--"             <!-- the script-end is redundant here since it would close the element -->
                   1106: 
                   1107: data2         = &lt;any string that doesn't contain a substring that matches not-data2&gt;
                   1108: not-data2     = <!-- script-end / -->script-start / "--&gt;"  <!-- the script-end is redundant here since it would close the element -->
                   1109: 
                   1110: data3         = &lt;any string that doesn't contain a substring that matches not-data3&gt;
                   1111: not-data3     = script-end / "--&gt;"
                   1112: 
                   1113: script-start  = lt       s c r i p t tag-end
                   1114: script-end    = lt slash s c r i p t tag-end
                   1115: 
                   1116: lt            =  %x003C ; U+003C LESS-THAN SIGN character (&lt;)
                   1117: slash         =  %x002F ; U+002F SOLIDUS character (/)
                   1118: 
                   1119: s             =  %x0053 ; U+0053 LATIN CAPITAL LETTER S
                   1120: s             =/ %x0073 ; U+0073 LATIN SMALL LETTER S
                   1121: c             =  %x0043 ; U+0043 LATIN CAPITAL LETTER C
                   1122: c             =/ %x0063 ; U+0063 LATIN SMALL LETTER C
                   1123: r             =  %x0052 ; U+0052 LATIN CAPITAL LETTER R
                   1124: r             =/ %x0072 ; U+0072 LATIN SMALL LETTER R
                   1125: i             =  %x0049 ; U+0049 LATIN CAPITAL LETTER I
                   1126: i             =/ %x0069 ; U+0069 LATIN SMALL LETTER I
                   1127: p             =  %x0050 ; U+0050 LATIN CAPITAL LETTER P
                   1128: p             =/ %x0070 ; U+0070 LATIN SMALL LETTER P
                   1129: t             =  %x0054 ; U+0054 LATIN CAPITAL LETTER T
                   1130: t             =/ %x0074 ; U+0074 LATIN SMALL LETTER T
                   1131: 
                   1132: tag-end       =  %x0009 ; U+0009 CHARACTER TABULATION
                   1133: tag-end       =/ %x000A ; U+000A LINE FEED (LF)
                   1134: tag-end       =/ %x000C ; U+000C FORM FEED (FF)
                   1135: tag-end       =/ %x0020 ; U+0020 SPACE
                   1136: tag-end       =/ %x002F ; U+002F SOLIDUS (/)
                   1137: tag-end       =/ %x003E ; U+003E GREATER-THAN SIGN (&gt;)</pre><p>When a <code><a href="#script">script</a></code> element contains <a href="#inline-documentation-for-external-scripts">script
                   1138:   documentation</a>, there are further restrictions on the contents
1.15      mike     1139:   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>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.1       mike     1140:   contents of the <code><a href="#script">script</a></code> element, if any, must be such
                   1141:   that the value of the <code title="dom-script-text"><a href="#dom-script-text">text</a></code> IDL
                   1142:   attribute, which is derived from the element's contents, matches the
                   1143:   <code title="">documentation</code> production in the following
                   1144:   ABNF, the character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a></p><pre>documentation = *( *( space / tab / comment ) [ line-comment ] newline )
                   1145: comment       = slash star *( not-star / star not-slash ) 1*star slash
                   1146: line-comment  = slash slash *not-newline
                   1147: 
                   1148: ; characters
                   1149: tab           = %x0009 ; U+0009 TAB
                   1150: newline       = %x000A ; U+000A LINE FEED (LF)
                   1151: space         = %x0020 ; U+0020 SPACE
                   1152: star          = %x002A ; U+002A ASTERISK (*)
                   1153: slash         = %x002F ; U+002F SOLIDUS (/)
                   1154: not-newline   = %x0000-0009 / %x000B-10FFFF
                   1155:                 ; a Unicode character other than U+000A LINE FEED (LF)
                   1156: not-star      = %x0000-0029 / %x002B-10FFFF
                   1157:                 ; a Unicode character other than U+002A ASTERISK (*)
                   1158: not-slash     = %x0000-002E / %x0030-10FFFF
                   1159:                 ; a Unicode character other than U+002F SOLIDUS (/)</pre><p class="note">This corresponds to putting the contents of the
                   1160:   element in JavaScript comments.</p><p class="note">This requirement is in addition to the earlier
                   1161:   restrictions on the syntax of contents of <code><a href="#script">script</a></code>
                   1162:   elements.</p><div class="example">
                   1163: 
                   1164:    <p>This allows authors to include documentation, such as license
                   1165:    information or API information, inside their documents while still
                   1166:    referring to external script files. The syntax is constrained so
                   1167:    that authors don't accidentally include what looks like valid
                   1168:    script while also providing a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute.</p>
                   1169: 
                   1170:    <pre>&lt;script src="cool-effects.js"&gt;
                   1171:  // create new instances using:
                   1172:  //    var e = new Effect();
                   1173:  // start the effect using .play, stop using .stop:
                   1174:  //    e.play();
                   1175:  //    e.stop();
                   1176: &lt;/script&gt;</pre>
                   1177: 
1.22      mike     1178:   </div><h4 id="the-noscript-element"><span class="secno">4.3.2 </span>The <dfn><code>noscript</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
1.1       mike     1179:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                   1180:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                   1181:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
1.16      mike     1182:    <dt>Contexts in which this element can be used:</dt>
1.1       mike     1183:    <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>
                   1184:    <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>
                   1185:    <dt>Content model:</dt>
                   1186:    <dd>When <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">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>
                   1187:    <dd>When <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">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>
                   1188:    <dd>Otherwise: text that conforms to the requirements given in the prose.</dd>
                   1189:    <dt>Content attributes:</dt>
                   1190:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
                   1191:    <dt>DOM interface:</dt>
                   1192:    <dd>Uses <code><a href="elements.html#htmlelement">HTMLElement</a></code>.</dd>
                   1193:   </dl><p>The <code><a href="#the-noscript-element">noscript</a></code> element <a href="rendering.html#represents">represents</a> nothing
                   1194:   if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a>, and
                   1195:   <a href="rendering.html#represents">represents</a> its children if <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a>. It is used
                   1196:   to present different markup to user agents that support scripting
                   1197:   and those that don't support scripting, by affecting how the
                   1198:   document is parsed.</p><p>When used in <a href="dom.html#html-documents">HTML documents</a>, the allowed content
                   1199:   model is as follows:</p><dl><dt>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element, if <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> for the
                   1200:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1201: 
                   1202:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only
                   1203:    <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>
                   1204:    elements.</p></dd>
                   1205: 
                   1206:    <dt>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element, if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
                   1207:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1208: 
                   1209:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
                   1210:    except that invoking the <a href="the-end.html#html-fragment-parsing-algorithm">HTML fragment parsing
                   1211:    algorithm</a> <!-- (which disables <script type="text/javascript"> execution) --> with
                   1212:    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
                   1213:    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
                   1214:    <code><a href="semantics.html#meta">meta</a></code> elements that would be conforming if they were
                   1215:    children of the <code><a href="#the-noscript-element">noscript</a></code> element, and no <a href="parsing.html#parse-error" title="parse error">parse errors</a>.</p></dd>
                   1216: 
                   1217:    <dt>Outside of <code><a href="semantics.html#the-head-element-0">head</a></code> elements, if <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> for the
                   1218:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1219: 
                   1220:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element's content model is
                   1221:    <a href="content-models.html#transparent">transparent</a>, with the additional restriction that a
                   1222:    <code><a href="#the-noscript-element">noscript</a></code> element must not have a <code><a href="#the-noscript-element">noscript</a></code>
                   1223:    element as an ancestor (that is, <code><a href="#the-noscript-element">noscript</a></code> can't be
                   1224:    nested).</p></dd>
                   1225: 
                   1226:    <dt>Outside of <code><a href="semantics.html#the-head-element-0">head</a></code> elements, if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
                   1227:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1228: 
                   1229:    <dd>
                   1230: 
                   1231:     <p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
                   1232:     except that the text must be such that running the following
                   1233:     algorithm results in a conforming document with no
                   1234:     <code><a href="#the-noscript-element">noscript</a></code> elements and no <code><a href="#script">script</a></code>
                   1235:     elements, and such that no step in the algorithm causes an
                   1236:     <a href="parsing.html#html-parser">HTML parser</a> to flag a <a href="parsing.html#parse-error">parse error</a>:</p>
                   1237: 
                   1238:     <ol><li>Remove every <code><a href="#script">script</a></code> element from the
                   1239:      document.</li>
                   1240: 
                   1241:      <li>Make a list of every <code><a href="#the-noscript-element">noscript</a></code> element in the
                   1242:      document. For every <code><a href="#the-noscript-element">noscript</a></code> element in that list,
                   1243:      perform the following steps:
                   1244: 
                   1245:       <ol><li>Let the <var title="">parent element</var> be the parent
                   1246:        element of the <code><a href="#the-noscript-element">noscript</a></code> element.</li>
                   1247: 
                   1248:        <li>Take all the children of the <var title="">parent element</var>
                   1249:        that come before the <code><a href="#the-noscript-element">noscript</a></code> element, and call these
                   1250:        elements <var title="">the before children</var>.</li>
                   1251: 
                   1252:        <li>Take all the children of the <var title="">parent element</var>
                   1253:        that come <em>after</em> the <code><a href="#the-noscript-element">noscript</a></code> element, and
                   1254:        call these elements <var title="">the after children</var>.</li>
                   1255: 
                   1256:        <li>Let <var title="">s</var> be the concatenation of all the
                   1257:        <a href="infrastructure.html#text-node">text node</a> children of the <code><a href="#the-noscript-element">noscript</a></code>
                   1258:        element.</li>
                   1259: 
                   1260:        <li>Set the <code title="dom-innerHTML"><a href="apis-in-html-documents.html#dom-innerhtml">innerHTML</a></code>
                   1261:        attribute of the <var title="">parent element</var> to the value
                   1262:        of <var title="">s</var>. (This, as a side-effect, causes the
                   1263:        <code><a href="#the-noscript-element">noscript</a></code> element to be removed from the
                   1264:        document.)</li>
                   1265: 
                   1266:        <li>Insert <var title="">the before children</var> at the start of
                   1267:        the <var title="">parent element</var>, preserving their original
                   1268:        relative order.</li>
                   1269: 
                   1270:        <li>Insert <var title="">the after children</var> at the end of the
                   1271:        <var title="">parent element</var>, preserving their original
                   1272:        relative order.</li>
                   1273: 
                   1274:       </ol></li>
                   1275: 
                   1276:     </ol></dd>
                   1277: 
                   1278:   </dl><p class="note">All these contortions are required because, for
                   1279:   historical reasons, the <code><a href="#the-noscript-element">noscript</a></code> element is handled
                   1280:   differently by the <a href="parsing.html#html-parser">HTML parser</a> based on whether <a href="parsing.html#scripting-flag" title="scripting flag">scripting was enabled or not</a> when the
                   1281:   parser was invoked.</p><p>The <code><a href="#the-noscript-element">noscript</a></code> element must not be used in <a href="dom.html#xml-documents">XML
                   1282:   documents</a>.</p><p class="note"><strong>The <code><a href="#the-noscript-element">noscript</a></code> element is only
                   1283:   effective in <a href="syntax.html#syntax">the HTML syntax</a>, it has no effect in
                   1284:   <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML syntax</a>.</strong></p><div class="impl">
                   1285: 
                   1286:   <p>The <code><a href="#the-noscript-element">noscript</a></code> element has no other requirements. In
                   1287:   particular, children of the <code><a href="#the-noscript-element">noscript</a></code> element are not
                   1288:   exempt from <a href="association-of-controls-and-forms.html#form-submission">form submission</a>, scripting, and so forth,
                   1289:   even when <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a>
                   1290:   for the element.</p>
                   1291: 
                   1292:   </div><div class="example">
                   1293: 
                   1294:    <p>In the following example, a <code><a href="#the-noscript-element">noscript</a></code> element is
                   1295:    used to provide fallback for a script.</p>
                   1296: 
                   1297:    <pre>&lt;form action="calcSquare.php"&gt;
                   1298:  &lt;p&gt;
                   1299:   &lt;label for=x&gt;Number&lt;/label&gt;:
                   1300:   &lt;input id="x" name="x" type="number"&gt;
                   1301:  &lt;/p&gt;
                   1302:  &lt;script&gt;
                   1303:   var x = document.getElementById('x');
                   1304:   var output = document.createElement('p');
                   1305:   output.textContent = 'Type a number; it will be squared right then!';
                   1306:   x.form.appendChild(output);
                   1307:   x.form.onsubmit = function () { return false; }
                   1308:   x.oninput = function () {
                   1309:     var v = x.valueAsNumber;
                   1310:     output.textContent = v + ' squared is ' + v * v;
                   1311:   };
                   1312:  &lt;/script&gt;
                   1313:  &lt;noscript&gt;
                   1314:   &lt;input type=submit value="Calculate Square"&gt;
                   1315:  &lt;/noscript&gt;
                   1316: &lt;/form&gt;</pre>
                   1317: 
                   1318:    <p>When script is disabled, a button appears to do the calculation
                   1319:    on the server side. When script is enabled, the value is computed
                   1320:    on-the-fly instead.</p>
                   1321: 
                   1322:    <p>The <code><a href="#the-noscript-element">noscript</a></code> element is a blunt
                   1323:    instrument. Sometimes, scripts might be enabled, but for some
                   1324:    reason the page's script might fail. For this reason, it's
                   1325:    generally better to avoid using <code><a href="#the-noscript-element">noscript</a></code>, and to
                   1326:    instead design the script to change the page from being a
                   1327:    scriptless page to a scripted page on the fly, as in the next
                   1328:    example:</p>
                   1329: 
                   1330:    <pre>&lt;form action="calcSquare.php"&gt;
                   1331:  &lt;p&gt;
                   1332:   &lt;label for=x&gt;Number&lt;/label&gt;:
                   1333:   &lt;input id="x" name="x" type="number"&gt;
                   1334:  &lt;/p&gt;
                   1335:  <strong>&lt;input id="submit" type=submit value="Calculate Square"&gt;</strong>
                   1336:  &lt;script&gt;
                   1337:   var x = document.getElementById('x');
                   1338:   var output = document.createElement('p');
                   1339:   output.textContent = 'Type a number; it will be squared right then!';
                   1340:   x.form.appendChild(output);
                   1341:   x.form.onsubmit = function () { return false; }
                   1342:   x.oninput = function () {
                   1343:     var v = x.valueAsNumber;
                   1344:     output.textContent = v + ' squared is ' + v * v;
                   1345:   };
                   1346: <strong>  var submit = document.getElementById('submit');
                   1347:   submit.parentNode.removeChild(submit);</strong>
                   1348:  &lt;/script&gt;
                   1349: &lt;/form&gt;</pre>
                   1350: 
                   1351:    <p>The above technique is also useful in XHTML, since
                   1352:    <code><a href="#the-noscript-element">noscript</a></code> is not supported in <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML
                   1353:    syntax</a>.</p>
                   1354: 
                   1355:   </div></body></html>

Webmaster