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

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

Webmaster