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

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

Webmaster