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

1.1       mike        1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
                      2: <!DOCTYPE html>
1.48      mike        3: <html lang="en-US-x-Hixie" class="split chapter"><head><title>4.3 Scripting &#8212; HTML5 </title><style type="text/css">
1.1       mike        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.33      mike      188:    fieldset { margin: 1em; padding: 0.5em 1em; }
                    189:    fieldset > legend + * { margin-top: 0; }
1.28      mike      190:    fieldset > :last-child { margin-bottom: 0; }
1.33      mike      191:    fieldset p { margin: 0.5em 0; }
                    192: 
1.47      mike      193:   </style><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><style type="text/css">
1.1       mike      194: 
                    195:    .applies thead th > * { display: block; }
                    196:    .applies thead code { display: block; }
                    197:    .applies tbody th { whitespace: nowrap; }
                    198:    .applies td { text-align: center; }
                    199:    .applies .yes { background: yellow; }
                    200: 
1.10      mike      201:    .matrix, .matrix td { border: hidden; text-align: right; }
1.1       mike      202:    .matrix { margin-left: 2em; }
                    203: 
                    204:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    205:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    206:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    207: 
1.17      mike      208:    td.eg { border-width: thin; text-align: center; }
                    209: 
1.1       mike      210:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    211:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    212:    #table-example-1 caption { padding-bottom: 0.5em; }
                    213:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    214:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    215:    #table-example-1 th { font-weight: normal; }
                    216:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    217:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    218:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    219:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    220:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    221:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    222:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    223:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    224:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    225:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    226: 
                    227:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    228:    .apple-table-examples * { font-family: "Times", serif; }
                    229:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    230:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    231:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    232:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    233:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    234:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    235:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
                    236:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    237:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    238:    .apple-table-examples sup { line-height: 0; }
                    239: 
                    240:    .details-example img { vertical-align: top; }
                    241: 
1.39      mike      242:    #base64-table {
                    243:      white-space: nowrap;
                    244:      font-size: 0.6em;
                    245:      column-width: 6em;
                    246:      column-count: 5;
                    247:      column-gap: 1em;
                    248:      -moz-column-width: 6em;
                    249:      -moz-column-count: 5;
                    250:      -moz-column-gap: 1em;
                    251:      -webkit-column-width: 6em;
                    252:      -webkit-column-count: 5;
                    253:      -webkit-column-gap: 1em;
                    254:    }
                    255:    #base64-table thead { display: none; }
                    256:    #base64-table * { border: none; }
                    257:    #base64-table tbody td:first-child:after { content: ':'; }
                    258:    #base64-table tbody td:last-child { text-align: right; }
                    259: 
1.1       mike      260:    #named-character-references-table {
1.24      mike      261:      white-space: nowrap;
1.1       mike      262:      font-size: 0.6em;
1.24      mike      263:      column-width: 30em;
1.1       mike      264:      column-gap: 1em;
1.24      mike      265:      -moz-column-width: 30em;
1.1       mike      266:      -moz-column-gap: 1em;
1.24      mike      267:      -webkit-column-width: 30em;
1.1       mike      268:      -webkit-column-gap: 1em;
                    269:    }
1.24      mike      270:    #named-character-references-table > table > tbody > tr > td:first-child + td,
1.1       mike      271:    #named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
                    272:    #named-character-references-table > table > tbody > tr > td:last-child:hover > span { position: absolute; top: auto; left: auto; margin-left: 0.5em; line-height: 1.2; font-size: 5em; border: outset; padding: 0.25em 0.5em; background: white; width: 1.25em; height: auto; text-align: center; }
1.24      mike      273:    #named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
1.1       mike      274: 
1.2       mike      275:    .glyph.control { color: red; }
                    276: 
1.4       mike      277:    @font-face {
                    278:      font-family: 'Essays1743';
                    279:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
                    280:    }
                    281:    @font-face {
                    282:      font-family: 'Essays1743';
                    283:      font-weight: bold;
                    284:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
                    285:    }
                    286:    @font-face {
                    287:      font-family: 'Essays1743';
                    288:      font-style: italic;
                    289:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
                    290:    }
                    291:    @font-face {
                    292:      font-family: 'Essays1743';
                    293:      font-style: italic;
                    294:      font-weight: bold;
                    295:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
                    296:    }
                    297: 
1.1       mike      298:   </style><style type="text/css">
                    299:    .domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
1.47      mike      300:   </style><link href="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script type="text/javascript">
                    301:    function getCookie(name) {
                    302:      var params = location.search.substr(1).split("&");
                    303:      for (var index = 0; index < params.length; index++) {
                    304:        if (params[index] == name)
                    305:          return "1";
                    306:        var data = params[index].split("=");
                    307:        if (data[0] == name)
                    308:          return unescape(data[1]);
                    309:      }
                    310:      var cookies = document.cookie.split("; ");
                    311:      for (var index = 0; index < cookies.length; index++) {
                    312:        var data = cookies[index].split("=");
                    313:        if (data[0] == name)
                    314:          return unescape(data[1]);
                    315:      }
                    316:      return null;
                    317:    }
                    318:   </script>
1.1       mike      319:   <script src="link-fixup.js"></script>
1.35      mike      320:   <link href="style.css" rel="stylesheet"><link href="semantics.html" title="4 The elements of HTML" rel="prev">
1.1       mike      321:   <link href="spec.html#contents" title="Table of contents" rel="index">
                    322:   <link href="sections.html" title="4.4 Sections" rel="next">
1.54    ! mike      323:   </head><body><div class="head" id="head">
1.1       mike      324:    <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      325: 
1.1       mike      326:    <h1>HTML5</h1>
                    327:    </div><div>
1.35      mike      328:    <a href="semantics.html" class="prev">4 The elements of HTML</a> &#8211;
1.1       mike      329:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.35      mike      330:    <a href="sections.html" class="next">4.4 Sections</a>
1.1       mike      331:   <ol class="toc"><li><ol><li><a href="scripting-1.html#scripting-1"><span class="secno">4.3 </span>Scripting</a>
1.50      mike      332:     <ol><li><a href="scripting-1.html#the-script-element"><span class="secno">4.3.1 </span>The <code>script</code> element</a>
1.49      mike      333:       <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><li><a href="scripting-1.html#scriptTagXSLT"><span class="secno">4.3.1.4 </span>Interaction of <code>script</code> elements and XSLT</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>
1.1       mike      334: 
1.15      mike      335:   <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      336:   scripting where possible, as declarative mechanisms are often more
                    337:   maintainable, and many users disable scripting.</p><div class="example">
                    338:    <p>For example, instead of using script to show or hide a section
                    339:    to show more details, the <code><a href="interactive-elements.html#the-details-element">details</a></code> element could be
                    340:    used.</p>
                    341:   </div><p>Authors are also encouraged to make their applications degrade
                    342:   gracefully in the absence of scripting support.</p><div class="example">
                    343:    <p>For example, if an author provides a link in a table header to
                    344:    dynamically resort the table, the link could also be made to
                    345:    function without scripts by requesting the sorted table from the
                    346:    server.</p>
1.50      mike      347:   </div><h4 id="the-script-element"><span class="secno">4.3.1 </span>The <dfn id="script"><code>script</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
1.1       mike      348:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                    349:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                    350:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
1.16      mike      351:    <dt>Contexts in which this element can be used:</dt>
1.1       mike      352:    <dd>Where <a href="content-models.html#metadata-content">metadata content</a> is expected.</dd>
                    353:    <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected.</dd>
                    354:    <dt>Content model:</dt>
                    355:    <dd>If there is no <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    356:    attribute, depends on the value of the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, but must match
                    357:    <a href="#restrictions-for-contents-of-script-elements">script content restrictions</a>.</dd>
                    358:    <dd>If there <em>is</em> a <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    359:    attribute, the element must be either empty or contain only
                    360:    <a href="#inline-documentation-for-external-scripts">script documentation</a> that also matches <a href="#restrictions-for-contents-of-script-elements">script
                    361:    content restrictions</a>.</dd>
                    362:    <dt>Content attributes:</dt>
                    363:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
                    364:    <dd><code title="attr-script-src"><a href="#attr-script-src">src</a></code></dd>
                    365:    <dd><code title="attr-script-async"><a href="#attr-script-async">async</a></code></dd>
                    366:    <dd><code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code></dd>
                    367:    <dd><code title="attr-script-type"><a href="#attr-script-type">type</a></code></dd>
                    368:    <dd><code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code></dd>
                    369:    <dt>DOM interface:</dt>
                    370:    <dd>
                    371: <pre class="idl">interface <dfn id="htmlscriptelement">HTMLScriptElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
                    372:            attribute DOMString <a href="#dom-script-src" title="dom-script-src">src</a>;
                    373:            attribute boolean <a href="#dom-script-async" title="dom-script-async">async</a>;
                    374:            attribute boolean <a href="#dom-script-defer" title="dom-script-defer">defer</a>;
                    375:            attribute DOMString <a href="#dom-script-type" title="dom-script-type">type</a>;
                    376:            attribute DOMString <a href="#dom-script-charset" title="dom-script-charset">charset</a>;
                    377:            attribute DOMString <a href="#dom-script-text" title="dom-script-text">text</a>;
                    378: };</pre>
                    379:    </dd>
1.50      mike      380:   </dl><p>The <code><a href="#the-script-element">script</a></code> element allows authors to include dynamic
1.1       mike      381:   script and data blocks in their documents. The element does not
                    382:   <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
                    383:   embedded inline or may be imported from an external file using the
                    384:   <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute. If the language
                    385:   is not that described by "<code title="">text/javascript</code>",
                    386:   then the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute must
1.41      mike      387:   be present, as described below. Whatever language is used, the
1.50      mike      388:   contents of the <code><a href="#the-script-element">script</a></code> element must conform with the
1.41      mike      389:   requirements of that language's specification.</p><p>When used to include data blocks (as opposed to scripts), the
1.1       mike      390:   data must be embedded inline, the format of the data must be given
1.41      mike      391:   using the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, the
                    392:   <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute must not be
1.50      mike      393:   specified, and the contents of the <code><a href="#the-script-element">script</a></code> element must
1.41      mike      394:   conform to the requirements defined for the format used.</p><p>The <dfn id="attr-script-type" title="attr-script-type"><code>type</code></dfn>
1.1       mike      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
1.50      mike      434:   parsing rules for <code><a href="#the-script-element">script</a></code> <a href="tree-construction.html#scriptTag">start</a>
1.48      mike      435:   and <a href="tree-construction.html#scriptEndTag">end</a> tags in HTML, <a href="tree-construction.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
1.1       mike      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
1.48      mike      442:   described below.</p><div class="impl">
1.1       mike      443: 
1.50      mike      444:   <p>A <code><a href="#the-script-element">script</a></code> element has several associated pieces of
1.1       mike      445:   state.</p>
                    446: 
                    447:   <p>The first is a flag indicating whether or not the script block
                    448:   has been <dfn id="already-started">"already started"</dfn>. Initially,
1.50      mike      449:   <code><a href="#the-script-element">script</a></code> elements must have this flag unset (script
1.1       mike      450:   blocks, when created, are not "already started"). When a
1.50      mike      451:   <code><a href="#the-script-element">script</a></code> element is <a href="infrastructure.html#concept-clone" title="concept-clone">cloned</a>, the "already started" flag, if
1.40      mike      452:   set, must be propagated to the clone when it is created.</p>
1.1       mike      453: 
                    454:   <p>The second is a flag indicating whether the element was
1.50      mike      455:   <dfn id="parser-inserted">"parser-inserted"</dfn>. Initially, <code><a href="#the-script-element">script</a></code>
1.1       mike      456:   elements must have this flag unset. It is set by the <a href="parsing.html#html-parser">HTML
1.50      mike      457:   parser</a> and the <a href="the-xhtml-syntax.html#xml-parser">XML parser</a> on <code><a href="#the-script-element">script</a></code>
1.1       mike      458:   elements they insert and affects the processing of those
                    459:   elements.</p>
                    460: 
1.39      mike      461:   <p>The third is a flag indicating whether the element will
1.50      mike      462:   <dfn id="force-async">"force-async"</dfn>. Initially, <code><a href="#the-script-element">script</a></code> elements
1.39      mike      463:   must have this flag set. It is unset by the <a href="parsing.html#html-parser">HTML parser</a>
1.50      mike      464:   and the <a href="the-xhtml-syntax.html#xml-parser">XML parser</a> on <code><a href="#the-script-element">script</a></code> elements they
                    465:   insert. In addition, whenever a <code><a href="#the-script-element">script</a></code> element whose
1.39      mike      466:   <a href="#force-async">"force-async"</a> flag is set has a <code title="attr-script-async"><a href="#attr-script-async">async</a></code> content attribute added, the
1.48      mike      467:   element's <a href="#force-async">"force-async"</a> flag must be unset.</p> 
1.39      mike      468:   <p>The fourth is a flag indicating whether or not the script block is
1.1       mike      469:   <dfn id="ready-to-be-parser-executed">"ready to be parser-executed"</dfn>. Initially,
1.50      mike      470:   <code><a href="#the-script-element">script</a></code> elements must have this flag unset (script
1.1       mike      471:   blocks, when created, are not "ready to be parser-executed"). This
                    472:   flag is used only for elements that are also
                    473:   <a href="#parser-inserted">"parser-inserted"</a>, to let the parser know when to
                    474:   execute the script.</p>
                    475: 
1.23      mike      476:   <p>The last few pieces of state are <dfn id="the-script-block-s-type"><var>the script block's
                    477:   type</var></dfn>, <dfn id="the-script-block-s-character-encoding"><var>the script block's character
                    478:   encoding</var></dfn>, and <dfn id="the-script-block-s-fallback-character-encoding"><var>the script block's fallback
                    479:   character encoding</var></dfn>. They are determined when the script
1.40      mike      480:   is prepared, based on the attributes on the element at that time,
1.50      mike      481:   and the <code><a href="infrastructure.html#document">Document</a></code> of the <code><a href="#the-script-element">script</a></code>
1.40      mike      482:   element.</p>
1.1       mike      483: 
1.50      mike      484:   <p>When a <code><a href="#the-script-element">script</a></code> element that is not marked as being
1.1       mike      485:   <a href="#parser-inserted">"parser-inserted"</a> experiences one of the events listed
1.50      mike      486:   in the following list, the user agent must synchronously <a href="#prepare-a-script" title="prepare a script">prepare</a> the <code><a href="#the-script-element">script</a></code>
1.1       mike      487:   element:</p>
                    488: 
1.50      mike      489:   <ul><li>The <code><a href="#the-script-element">script</a></code> element gets <a href="infrastructure.html#insert-an-element-into-a-document" title="insert an
1.1       mike      490:    element into a document">inserted into a document</a>.</li>
                    491: 
1.50      mike      492:    <li>The <code><a href="#the-script-element">script</a></code> element is <a href="infrastructure.html#in-a-document">in a
1.1       mike      493:    <code>Document</code></a> and its child nodes are changed.</li>
                    494: 
1.50      mike      495:    <li>The <code><a href="#the-script-element">script</a></code> element is <a href="infrastructure.html#in-a-document">in a
1.1       mike      496:    <code>Document</code></a> and has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute set where previously
                    497:    the element had no such attribute.</li>
                    498: 
1.40      mike      499:   </ul><p>To <dfn id="prepare-a-script" title="prepare a script">prepare a script</dfn>, the user
                    500:   agent must act as follows:</p>
1.1       mike      501: 
1.19      mike      502:   <ol><li>
1.16      mike      503: 
1.50      mike      504:     <p>If the <code><a href="#the-script-element">script</a></code> element is marked as having
1.19      mike      505:     <a href="#already-started">"already started"</a>, then the user agent must abort
                    506:     these steps at this point. The script is not executed.</p>
1.16      mike      507: 
                    508:    </li>
                    509: 
1.18      mike      510:    <li>
                    511: 
                    512:     <p>If the element has its <a href="#parser-inserted">"parser-inserted"</a> flag set,
                    513:     then set <var title="">was-parser-inserted</var> to true and unset
                    514:     the element's <a href="#parser-inserted">"parser-inserted"</a> flag. Otherwise, set
                    515:     <var title="">was-parser-inserted</var> to false.</p>
                    516: 
                    517:     <p class="note">This is done so that if parser-inserted
1.50      mike      518:     <code><a href="#the-script-element">script</a></code> elements fail to run when the parser tries to
1.18      mike      519:     run them, e.g. because they are empty or specify an unsupported
                    520:     scripting language, another script can later mutate them and cause
                    521:     them to run again.</p>
                    522: 
1.48      mike      523:     
1.18      mike      524: 
                    525:    </li>
                    526: 
1.39      mike      527:    <li>
                    528: 
                    529:     <p>If <var title="">was-parser-inserted</var> is true and the
                    530:     element does not have an <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute, then set the
                    531:     element's <a href="#force-async">"force-async"</a> flag to true.</p>
                    532: 
                    533:     <p class="note">This is done so that if a parser-inserted
1.50      mike      534:     <code><a href="#the-script-element">script</a></code> element fails to run when the parser tries to
1.39      mike      535:     run it, but it is later executed after a script dynamically
                    536:     updates it, it will execute asynchronously even if the
                    537:     <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute isn't
                    538:     set.</p>
                    539: 
                    540:    </li>
                    541: 
1.16      mike      542:    <li id="script-processing-empty">
                    543: 
                    544:     <p>If the element has no <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
1.18      mike      545:     attribute, and its child nodes, if any, consist only of comment
                    546:     nodes and empty <a href="infrastructure.html#text-node" title="text node">text nodes</a>, then
                    547:     the user agent must abort these steps at this point. The script is
                    548:     not executed.</p>
1.16      mike      549: 
                    550:    </li>
                    551: 
1.25      mike      552:    <li>
                    553: 
                    554:     <p>If the element is not <a href="infrastructure.html#in-a-document">in a <code>Document</code></a>,
                    555:     then the user agent must abort these steps at this point. The
                    556:     script is not executed.</p>
                    557: 
                    558:    </li>
                    559: 
1.16      mike      560:    <li id="script-processing-prepare">
1.1       mike      561: 
                    562:     <p>If either:</p>
                    563: 
1.50      mike      564:     <ul class="brief"><li>the <code><a href="#the-script-element">script</a></code> element has a <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute and its value is
1.1       mike      565:      the empty string, or</li>
                    566: 
1.50      mike      567:      <li>the <code><a href="#the-script-element">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
1.1       mike      568:      <em>that</em> attribute's value is the empty string, or</li>
                    569: 
1.50      mike      570:      <li>the <code><a href="#the-script-element">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>
1.1       mike      571: 
                    572:     </ul><p>...let <var><a href="#the-script-block-s-type">the script block's type</a></var> for this
1.50      mike      573:     <code><a href="#the-script-element">script</a></code> element be "<code title="">text/javascript</code>".</p>
1.1       mike      574: 
1.50      mike      575:     <p>Otherwise, if the <code><a href="#the-script-element">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
                    576:     script block's type</a></var> for this <code><a href="#the-script-element">script</a></code> element be
1.1       mike      577:     the value of that attribute with any leading or trailing sequences
                    578:     of <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>
                    579:     removed.</p>
                    580: 
                    581:     <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
1.50      mike      582:     <var><a href="#the-script-block-s-type">the script block's type</a></var> for this <code><a href="#the-script-element">script</a></code>
1.48      mike      583:     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> 
1.1       mike      584:     <p class="note">The <code title="attr-script-language"><a href="obsolete.html#attr-script-language">language</a></code> attribute is never
                    585:     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>
                    586: 
                    587:    </li>
                    588: 
1.16      mike      589:    <li>
                    590: 
                    591:     <p>If the user agent does not <a href="#support-the-scripting-language">support the scripting
                    592:     language</a> given by <var><a href="#the-script-block-s-type">the script block's type</a></var> for
1.50      mike      593:     this <code><a href="#the-script-element">script</a></code> element, then the user agent must abort
1.16      mike      594:     these steps at this point. The script is not executed.</p>
                    595: 
                    596:    </li>
                    597: 
1.39      mike      598:    <li>
1.18      mike      599: 
1.39      mike      600:     <p>If <var title="">was-parser-inserted</var> is true, then flag
                    601:     the element as <a href="#parser-inserted">"parser-inserted"</a> again, and set the
                    602:     element's <a href="#force-async">"force-async"</a> flag to false.</p>
1.18      mike      603: 
                    604:    </li>
                    605: 
1.39      mike      606:    <li id="script-processing-start">
1.18      mike      607: 
1.39      mike      608:     <p>The user agent must set the element's <a href="#already-started">"already
                    609:     started"</a> flag.</p>
1.18      mike      610: 
1.40      mike      611:     <p class="note">The state of the element at this moment <a href="#establish-script-block-source">is later used</a> to
                    612:     determine the script source.</p>
                    613: 
                    614:    </li>
                    615: 
                    616:    <li>
                    617: 
                    618:     <p>If the element is flagged as <a href="#parser-inserted">"parser-inserted"</a>,
                    619:     but the element's <code><a href="infrastructure.html#document">Document</a></code> is not the
                    620:     <code><a href="infrastructure.html#document">Document</a></code> of the parser that created the element, then
                    621:     abort these steps.</p>
                    622: 
1.18      mike      623:    </li>
                    624: 
1.19      mike      625:    <li id="script-processing-noscript">
                    626: 
                    627:     <p>If <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is
1.50      mike      628:     disabled</a> for the <code><a href="#the-script-element">script</a></code> element, then the user
1.19      mike      629:     agent must abort these steps at this point. The script is not
                    630:     executed.</p>
                    631: 
1.40      mike      632:     <p class="note">The definition of <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> means
                    633:     that, amongst others, the following scripts will not execute:
                    634:     scripts in <code>XMLHttpRequest</code>'s <code title="dom-XMLHttpRequest-responseXML">responseXML</code>
1.49      mike      635:     documents, scripts in <code>DOMParser</code>-created documents,
                    636:     scripts in documents created by <code>XSLTProcessor</code>'s <code title="dom-XSLTProcessor-transformToDocument">transformToDocument</code>
                    637:     feature, and scripts that are first inserted by a script into a
1.40      mike      638:     <code><a href="infrastructure.html#document">Document</a></code> that was created using the <code title="dom-DOMImplementation-createDocument"><a href="infrastructure.html#dom-domimplementation-createdocument">createDocument()</a></code>
1.48      mike      639:     API. <a href="references.html#refsXHR">[XHR]</a> <a href="references.html#refsDOMPARSER">[DOMPARSER]</a>  <a href="references.html#refsDOMCORE">[DOMCORE]</a></p>
1.40      mike      640: 
                    641: 
1.19      mike      642:    </li>
                    643: 
1.1       mike      644:    <li id="script-processing-for">
                    645: 
1.50      mike      646:     <p>If the <code><a href="#the-script-element">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
1.1       mike      647:     substeps:</p>
                    648: 
                    649:     <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>
                    650: 
                    651:      <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>
                    652: 
                    653:      <li><p><a href="common-microsyntaxes.html#strip-leading-and-trailing-whitespace">Strip leading and trailing whitespace</a> from
                    654:      <var title="">event</var> and <var title="">for</var>.</p></li>
                    655: 
                    656:      <li><p>If <var title="">for</var> is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                    657:      case-insensitive</a> match for the string "<code title="">window</code>", then the user agent must abort these
                    658:      steps at this point. The script is not executed.</p></li>
                    659: 
                    660:      <li><p>If <var title="">event</var> is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                    661:      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
                    662:      steps at this point. The script is not executed.</p></li>
                    663: 
                    664:     </ol></li>
                    665: 
1.19      mike      666:    <li id="script-processing-encoding">
                    667: 
1.50      mike      668:     <p>If the <code><a href="#the-script-element">script</a></code> element has a <code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code> attribute, then let
1.19      mike      669:     <var><a href="#the-script-block-s-character-encoding">the script block's character encoding</a></var> for this
1.50      mike      670:     <code><a href="#the-script-element">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>
1.19      mike      671: 
1.23      mike      672:     <p>Otherwise, let <var><a href="#the-script-block-s-fallback-character-encoding">the script block's fallback character
1.50      mike      673:     encoding</a></var> for this <code><a href="#the-script-element">script</a></code> element be the same as
1.23      mike      674:     <a href="dom.html#document-s-character-encoding" title="document's character encoding">the encoding of the
                    675:     document itself</a>.</p>
                    676: 
                    677:     <p class="note">Only one of these two pieces of state is set.</p>
1.19      mike      678: 
                    679:    </li>
                    680: 
1.1       mike      681:    <li id="script-processing-src-prepare">
                    682: 
                    683:     <p>If the element has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    684:     attribute whose value is not the empty string, then the value of
                    685:     that attribute must be <a href="urls.html#resolve-a-url" title="resolve a url">resolved</a>
                    686:     relative to the element, and if that is successful, the specified
                    687:     resource must then be <a href="fetching-resources.html#fetch" title="fetch">fetched</a>, from the
                    688:     <a href="origin-0.html#origin">origin</a> of the element's <code><a href="infrastructure.html#document">Document</a></code>.</p>
1.48      mike      689:     
1.1       mike      690: 
                    691:     <p>If the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute's
                    692:     value is the empty string or if it could not be resolved, then the
                    693:     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
                    694:     event</a> named <code title="event-error">error</code> at the
                    695:     element, and abort these steps.</p>
                    696: 
                    697:     <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>
                    698:     URL</a>, then the user agent must not, despite the requirements
                    699:     in the definition of the <a href="fetching-resources.html#fetch" title="fetch">fetching</a>
                    700:     algorithm, actually execute the script in the URL; instead the
                    701:     user agent must act as if it had received an empty HTTP 400
                    702:     response.</p>
                    703: 
                    704:     <p>For performance reasons, user agents may start fetching the
                    705:     script as soon as the attribute is set, instead, in the hope that
                    706:     the element will be inserted into the document. Either way, once
                    707:     the element is <a href="infrastructure.html#insert-an-element-into-a-document" title="insert an element into a
                    708:     document">inserted into the document</a>, the load must have
                    709:     started. If the UA performs such prefetching, but the element is
                    710:     never inserted in the document, or the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is dynamically
1.48      mike      711:     changed, then the
1.1       mike      712:     user agent will not execute the script, and the fetching process
                    713:     will have been effectively wasted.</p>
                    714: 
                    715:    </li>
                    716: 
1.48      mike      717:    
1.1       mike      718:    <li>
                    719: 
                    720:     <p>Then, the first of the following options that describes the
                    721:     situation must be followed:</p>
                    722: 
                    723:     <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
                    724:      a <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute, and the
                    725:      element has been flagged as <a href="#parser-inserted">"parser-inserted"</a>, and
                    726:      the element does not have an <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute</dt>
                    727: 
                    728:      <dd>
                    729: 
                    730:       <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
                    731:       scripts that will execute when the document has finished
1.20      mike      732:       parsing</dfn> associated with the <code><a href="infrastructure.html#document">Document</a></code> of the
                    733:       parser that created the element.</p>
1.1       mike      734: 
                    735:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    736:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    737:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
                    738:       algorithm</a> has completed must set the element's
                    739:       <a href="#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag. The parser will
                    740:       handle executing the script.</p>
                    741: 
                    742:      </dd>
                    743: 
                    744: 
                    745:      <dt id="script-processing-parser-inserted">If the element has a
                    746:      <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute, and the
                    747:      element has been flagged as <a href="#parser-inserted">"parser-inserted"</a>, and
                    748:      the element does not have an <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute</dt>
                    749: 
                    750:      <dd>
                    751: 
                    752:       <p>The element is the <a href="#pending-parsing-blocking-script">pending parsing-blocking
1.20      mike      753:       script</a> of the <code><a href="infrastructure.html#document">Document</a></code> of the parser that
                    754:       created the element. (There can only be one such script per
                    755:       <code><a href="infrastructure.html#document">Document</a></code> at a time.)</p>
1.1       mike      756: 
                    757:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    758:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    759:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
                    760:       algorithm</a> has completed must set the element's
                    761:       <a href="#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag. The parser will
                    762:       handle executing the script.</p>
                    763: 
                    764:      </dd>
                    765: 
                    766: 
                    767:      <dt id="script-processing-style-delayed">If the element does not
1.33      mike      768:      have a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute, and
                    769:      the element has been flagged as <a href="#parser-inserted">"parser-inserted"</a>,
                    770:      and the <code><a href="infrastructure.html#document">Document</a></code> of the <a href="parsing.html#html-parser">HTML parser</a> or
1.50      mike      771:      <a href="the-xhtml-syntax.html#xml-parser">XML parser</a> that created the <code><a href="#the-script-element">script</a></code>
1.33      mike      772:      element <a href="semantics.html#has-a-style-sheet-that-is-blocking-scripts">has a style sheet that is blocking
                    773:      scripts</a></dt>
1.1       mike      774: 
                    775:      <dd>
                    776: 
                    777:       <p>The element is the <a href="#pending-parsing-blocking-script">pending parsing-blocking
1.20      mike      778:       script</a> of the <code><a href="infrastructure.html#document">Document</a></code> of the parser that
                    779:       created the element. (There can only be one such script per
                    780:       <code><a href="infrastructure.html#document">Document</a></code> at a time.)</p>
1.1       mike      781: 
                    782:       <p>Set the element's <a href="#ready-to-be-parser-executed">"ready to be parser-executed"</a>
                    783:       flag. The parser will handle executing the script.</p>
                    784: 
                    785:      </dd>
                    786: 
                    787: 
1.39      mike      788:      <dt id="script-processing-src-sync">If the element has a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute, does not have an
                    789:      <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute, and does
                    790:      not have the <a href="#force-async">"force-async"</a> flag set</dt>
                    791: 
                    792:      <dd>
                    793: 
                    794:       <p>The element must be added to the end of the <dfn id="list-of-scripts-that-will-execute-in-order-as-soon-as-possible">list of
                    795:       scripts that will execute in order as soon as possible</dfn>
                    796:       associated with the <code><a href="infrastructure.html#document">Document</a></code> of the
1.50      mike      797:       <code><a href="#the-script-element">script</a></code> element at the time the <a href="#prepare-a-script">prepare a
1.39      mike      798:       script</a> algorithm started.</p>
                    799: 
                    800:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    801:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    802:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
                    803:       algorithm</a> has completed must run the following steps:</p>
                    804: 
                    805:       <ol><li><p>If the element is not now the first element in the
                    806:        <a href="#list-of-scripts-that-will-execute-in-order-as-soon-as-possible">list of scripts that will execute in order as soon as
                    807:        possible</a> to which it was added above, then mark the
                    808:        element as ready but abort these steps without executing the
                    809:        script yet.</p></li>
                    810: 
1.40      mike      811:        <li><p><i>Execution</i>: <a href="#execute-the-script-block">Execute the script block</a>
                    812:        corresponding to the first script element in this <a href="#list-of-scripts-that-will-execute-in-order-as-soon-as-possible">list of
                    813:        scripts that will execute in order as soon as
                    814:        possible</a>.</p></li>
1.39      mike      815: 
                    816:        <li><p>Remove the first element from this <a href="#list-of-scripts-that-will-execute-in-order-as-soon-as-possible">list of scripts
                    817:        that will execute in order as soon as possible</a>.</p></li>
                    818: 
                    819:        <li><p>If this <a href="#list-of-scripts-that-will-execute-in-order-as-soon-as-possible">list of scripts that will execute in order
                    820:        as soon as possible</a> is still not empty and the first
                    821:        entry has already been marked as ready, then jump back to the
                    822:        step labeled <i>execution</i>.</p></li>
                    823: 
                    824:       </ol></dd>
                    825: 
                    826: 
1.1       mike      827:      <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>
                    828: 
                    829:      <dd>
                    830: 
                    831:       <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      832:       will execute as soon as possible</dfn> of the
1.50      mike      833:       <code><a href="infrastructure.html#document">Document</a></code> of the <code><a href="#the-script-element">script</a></code> element at the
1.40      mike      834:       time the <a href="#prepare-a-script">prepare a script</a> algorithm started.</p>
1.1       mike      835: 
                    836:       <p>The <a href="webappapis.html#concept-task" title="concept-task">task</a> that the
                    837:       <a href="webappapis.html#networking-task-source">networking task source</a> places on the <a href="webappapis.html#task-queue">task
                    838:       queue</a> once the <a href="fetching-resources.html#fetch" title="fetch">fetching
1.40      mike      839:       algorithm</a> has completed must <a href="#execute-the-script-block">execute the script
                    840:       block</a> and then remove the element from the <a href="#set-of-scripts-that-will-execute-as-soon-as-possible">set of
                    841:       scripts that will execute as soon as possible</a>.</p>
1.1       mike      842: 
                    843:      </dd>
                    844: 
                    845: 
                    846:      <dt id="script-processing-inline">Otherwise</dt>
                    847: 
1.40      mike      848:      <dd>The user agent must immediately <a href="#execute-the-script-block">execute the script
                    849:      block</a>, even if other scripts are already executing.</dd>
1.1       mike      850: 
                    851:     </dl></li>
                    852: 
1.48      mike      853:   </ol><p>Fetching an external script must <a href="the-end.html#delay-the-load-event">delay the load
1.1       mike      854:   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
                    855:   task">queued</a> by the <a href="webappapis.html#networking-task-source">networking task source</a> once
                    856:   the resource has been <a href="fetching-resources.html#fetch" title="fetch">fetched</a> (defined
                    857:   above) has been run.</p>
                    858: 
1.20      mike      859:   <p>The <dfn id="pending-parsing-blocking-script">pending parsing-blocking script</dfn> of a
                    860:   <code><a href="infrastructure.html#document">Document</a></code> is used by the <code><a href="infrastructure.html#document">Document</a></code>'s
                    861:   parser(s).</p>
1.1       mike      862: 
1.50      mike      863:   <p class="note">If a <code><a href="#the-script-element">script</a></code> element that blocks a
1.26      mike      864:   parser gets moved to another <code><a href="infrastructure.html#document">Document</a></code> before it would
                    865:   normally have stopped blocking that parser, it nonetheless continues
                    866:   blocking that parser until the condition that causes it to be
                    867:   blocking the parser no longer applies (e.g. if the script is a
                    868:   <a href="#pending-parsing-blocking-script">pending parsing-blocking script</a> because there was
                    869:   <a href="semantics.html#a-style-sheet-that-is-blocking-scripts">a style sheet that is blocking scripts</a> when it was
                    870:   parsed, but then the script is moved to another
                    871:   <code><a href="infrastructure.html#document">Document</a></code> before the style sheet loads, the script still
                    872:   blocks the parser until the style sheets are all loaded, at which
                    873:   time the script executes and the parser is unblocked).</p>
                    874: 
1.48      mike      875:   
1.40      mike      876:   <p>When the user agent is required to <dfn id="execute-the-script-block" title="execute the script
                    877:   block">execute a script block</dfn>, it must run the following
                    878:   steps:</p>
                    879: 
                    880:   <ol><li>
                    881: 
                    882:     <p>If the element is flagged as <a href="#parser-inserted">"parser-inserted"</a>,
                    883:     but the element's <code><a href="infrastructure.html#document">Document</a></code> is not the
                    884:     <code><a href="infrastructure.html#document">Document</a></code> of the parser that created the element, then
                    885:     abort these steps.</p>
1.1       mike      886: 
1.40      mike      887:    </li>
                    888: 
                    889:    <li>
1.1       mike      890: 
1.40      mike      891:     <p>Jump to the appropriate set of steps from the list below:</p>
1.1       mike      892: 
1.40      mike      893:     <dl class="switch"><dt>If the load resulted in an error (for example a DNS error, or
                    894:      an HTTP 404 error)</dt>
1.1       mike      895: 
1.40      mike      896:      <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
                    897:      <code title="event-error">error</code> at the element.</p></dd>
                    898: 
                    899:      <dt>If the load was successful</dt>
                    900: 
                    901:      <!-- SCRIPT EXEC -->
                    902:      <dd>
                    903: 
1.43      mike      904:       <p>Executing the script block must consist of running the
1.40      mike      905:       following steps. For the purposes of these steps, the script is
                    906:       considered to be from an <i>external file</i> if, while the
                    907:       <a href="#prepare-a-script">prepare a script</a> algorithm above was running for
1.50      mike      908:       this script, the <code><a href="#the-script-element">script</a></code> element had a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute specified.</p>
1.1       mike      909: 
1.40      mike      910:       <ol><li id="establish-script-block-source">
1.27      mike      911: 
1.40      mike      912:         <p>Initialize <dfn id="the-script-block-s-source"><var>the script block's source</var></dfn>
                    913:         as follows:</p>
1.1       mike      914: 
1.40      mike      915:         <dl class="switch"><dt>If the script is from an external file and <var><a href="#the-script-block-s-type">the
                    916:          script block's type</a></var> is a text-based language</dt>
1.1       mike      917: 
1.40      mike      918:          <dd>
1.1       mike      919: 
1.40      mike      920:           <p>The contents of that file, interpreted as string of
                    921:           Unicode characters, are the script source.</p>
1.1       mike      922: 
1.40      mike      923:           <p>To obtain the string of Unicode characters, the user
                    924:           agent run the following steps:</p>
1.1       mike      925: 
1.40      mike      926:           <ol><li><p>If the resource's <a href="fetching-resources.html#content-type" title="Content-Type">Content
                    927:            Type metadata</a>, if any, specifies a character
                    928:            encoding, and the user agent supports that encoding, then
                    929:            let <var title="">character encoding</var> be that
                    930:            encoding, and jump to the bottom step in this series of
                    931:            steps.</p></li>
1.1       mike      932: 
1.40      mike      933:            <li><p>If the algorithm above set <var><a href="#the-script-block-s-character-encoding">the script block's
                    934:            character encoding</a></var>, then let <var title="">character
                    935:            encoding</var> be that encoding, and jump to the bottom
                    936:            step in this series of steps.</p></li>
1.23      mike      937: 
1.40      mike      938:            <li><p>For each of the rows in the following table,
                    939:            starting with the first one and going down, if the file has
                    940:            as many or more bytes available than the number of bytes in
                    941:            the first column, and the first bytes of the file match the
                    942:            bytes given in the first column, then set <var title="">character encoding</var> to the encoding given in
                    943:            the cell in the second column of that row, and jump to the
                    944:            bottom step in this series of steps:</p>
1.23      mike      945: 
1.48      mike      946:             
1.40      mike      947:             <table id="table-script-bom"><thead><tr><th>Bytes in Hexadecimal
                    948:                </th><th>Encoding
1.48      mike      949:              </th></tr></thead><tbody><tr><td>FE FF
1.40      mike      950:                </td><td>Big-endian UTF-16
                    951:               </td></tr><tr><td>FF FE
                    952:                </td><td>Little-endian UTF-16
                    953:               </td></tr><tr><td>EF BB BF
                    954:                </td><td>UTF-8
1.48      mike      955:                 </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order
1.40      mike      956:             Marks (BOMs).</p>
1.23      mike      957: 
1.40      mike      958:            </li>
1.23      mike      959: 
1.40      mike      960:            <li><p>Let <var title="">character encoding</var> be
                    961:            <var><a href="#the-script-block-s-fallback-character-encoding">the script block's fallback character
                    962:            encoding</a></var>.</p></li>
1.23      mike      963: 
1.40      mike      964:            <li><p>Convert the file to Unicode using <var>character
                    965:            encoding</var>, following the rules for doing so given by
                    966:            the specification for <var><a href="#the-script-block-s-type">the script block's
                    967:            type</a></var>.</p></li>
1.23      mike      968: 
1.40      mike      969:           </ol></dd>
1.23      mike      970: 
1.40      mike      971:          <dt>If the script is from an external file and <var><a href="#the-script-block-s-type">the
                    972:          script block's type</a></var> is an XML-based language</dt>
1.1       mike      973: 
1.40      mike      974:          <dd>
1.1       mike      975: 
1.40      mike      976:           <p>The external file is the script source. When it is later
                    977:           executed, it must be interpreted in a manner consistent with
                    978:           the specification defining the language given by <var><a href="#the-script-block-s-type">the
                    979:           script block's type</a></var>.</p>
1.1       mike      980: 
1.40      mike      981:          </dd>
1.1       mike      982: 
1.40      mike      983:          <dt>If the script is inline and <var><a href="#the-script-block-s-type">the script block's
                    984:          type</a></var> is a text-based language</dt>
1.1       mike      985: 
1.40      mike      986:          <dd>
1.1       mike      987: 
1.40      mike      988:           <p>The value of the <code title="dom-script-text"><a href="#dom-script-text">text</a></code> IDL attribute at the
                    989:           time the element's <a href="#already-started">"already started"</a> flag was
                    990:           last set is the script source.</p>
1.1       mike      991: 
1.40      mike      992:          </dd>
1.1       mike      993: 
1.40      mike      994:          <dt>If the script is inline and <var><a href="#the-script-block-s-type">the script block's
                    995:          type</a></var> is an XML-based language</dt>
1.1       mike      996: 
1.40      mike      997:          <dd>
1.1       mike      998: 
1.50      mike      999:           <p>The child nodes of the <code><a href="#the-script-element">script</a></code> element at the
1.40      mike     1000:           time the element's <a href="#already-started">"already started"</a> flag was
                   1001:           last set are the script source.</p>
1.1       mike     1002: 
1.40      mike     1003:          </dd>
1.1       mike     1004: 
1.40      mike     1005:         </dl></li>
1.1       mike     1006: 
1.40      mike     1007:        <li>
1.1       mike     1008: 
1.40      mike     1009:         <p>If the script is from an external file, then increment the
                   1010:         <a href="apis-in-html-documents.html#ignore-destructive-writes-counter">ignore-destructive-writes counter</a> of the
1.50      mike     1011:         <code><a href="#the-script-element">script</a></code> element's <code><a href="infrastructure.html#document">Document</a></code>. Let <var title="">neutralized doc</var> be that
1.40      mike     1012:         <code><a href="infrastructure.html#document">Document</a></code>.</p>
1.1       mike     1013: 
1.40      mike     1014:        </li>
1.7       mike     1015: 
1.40      mike     1016:        <li>
1.7       mike     1017: 
1.40      mike     1018:         <p><a href="webappapis.html#create-a-script-from-a-node" title="create a script from a node">Create a
1.50      mike     1019:         script</a> from the <code><a href="#the-script-element">script</a></code> element node, using
1.40      mike     1020:         <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
                   1021:         block's type</a></var>.</p>
1.7       mike     1022: 
1.40      mike     1023:         <p class="note">This is where the script is compiled and
                   1024:         actually executed.</p>
1.1       mike     1025: 
1.40      mike     1026:        </li>
1.1       mike     1027: 
1.40      mike     1028:        <li>
1.1       mike     1029: 
1.40      mike     1030:         <p>Decrement the <a href="apis-in-html-documents.html#ignore-destructive-writes-counter">ignore-destructive-writes
                   1031:         counter</a> of <var title="">neutralized doc</var>, if it
                   1032:         was incremented in the earlier step.</p>
1.1       mike     1033: 
1.40      mike     1034:        </li>
1.7       mike     1035: 
1.40      mike     1036:        <li>
1.7       mike     1037: 
1.40      mike     1038:         <p>If the script is from an external file, <a href="webappapis.html#fire-a-simple-event">fire a simple
                   1039:         event</a> named <code title="event-load">load</code> at the
1.50      mike     1040:         <code><a href="#the-script-element">script</a></code> element.</p>
1.7       mike     1041: 
1.40      mike     1042:         <p>Otherwise, the script is internal; <a href="webappapis.html#queue-a-task">queue a
1.50      mike     1043:         task</a> 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="#the-script-element">script</a></code>
1.40      mike     1044:         element.</p>
1.1       mike     1045: 
1.40      mike     1046:        </li>
1.1       mike     1047: 
1.40      mike     1048:       </ol></dd>
1.1       mike     1049: 
1.40      mike     1050:     </dl></li>
1.1       mike     1051: 
1.40      mike     1052:   </ol><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>, and <dfn id="dom-script-defer" title="dom-script-defer"><code>defer</code></dfn>, each must
1.1       mike     1053:   <a href="common-dom-interfaces.html#reflect">reflect</a> the respective content attributes of the same
                   1054:   name.</p>
                   1055: 
1.39      mike     1056:   <p>The <dfn id="dom-script-async" title="dom-script-async"><code>async</code></dfn> IDL
                   1057:   attribute controls whether the element will execute asynchronously
                   1058:   or not. If the element's <a href="#force-async">"force-async"</a> flag is set,
                   1059:   then, on getting, the <code title="dom-script-async"><a href="#dom-script-async">async</a></code>
                   1060:   IDL attribute must return true, and on setting, the
                   1061:   <a href="#force-async">"force-async"</a> flag must first be unset, and then the
                   1062:   content attribute must be removed if the IDL attribute's new value
                   1063:   is false, and must be set to the empty string if the IDL attribute's
                   1064:   new value is true. If the element's <a href="#force-async">"force-async"</a> flag
                   1065:   is <em>not</em> set, the IDL attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the
                   1066:   <code title="attr-script-async"><a href="#attr-script-async">async</a></code> content attribute.</p>
                   1067: 
1.1       mike     1068:   </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>
                   1069: 
                   1070:    <dd>
                   1071: 
                   1072:     <p>Returns the contents of the element, ignoring child nodes that
                   1073:     aren't <a href="infrastructure.html#text-node" title="text node">text nodes</a>.</p>
                   1074: 
                   1075:     <p>Can be set, to replace the element's children with the given
                   1076:     value.</p>
                   1077: 
                   1078:    </dd>
                   1079: 
                   1080:   </dl><div class="impl">
                   1081: 
                   1082:   <p>The IDL attribute <dfn id="dom-script-text" title="dom-script-text"><code>text</code></dfn> must return a
                   1083:   concatenation of the contents of all the <a href="infrastructure.html#text-node" title="text
                   1084:   node">text nodes</a> that are direct children of the
1.50      mike     1085:   <code><a href="#the-script-element">script</a></code> element (ignoring any other nodes such as
1.1       mike     1086:   comments or elements), in tree order. On setting, it must act the
                   1087:   same way as the <code><a href="infrastructure.html#textcontent">textContent</a></code> IDL attribute.</p>
                   1088: 
                   1089:   </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,
1.50      mike     1090:   <code><a href="#the-script-element">script</a></code> elements execute (typically synchronously), but
1.1       mike     1091:   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
                   1092:   execute at all.</p><div class="example">
                   1093: 
1.50      mike     1094:    <p>In this example, two <code><a href="#the-script-element">script</a></code> elements are used. One
1.1       mike     1095:    embeds an external script, and the other includes some data.</p>
                   1096: 
                   1097:    <pre>&lt;script src="game-engine.js"&gt;&lt;/script&gt;
                   1098: &lt;script type="text/x-game-map"&gt;
                   1099: ........U.........e
                   1100: o............A....e
                   1101: .....A.....AAA....e
                   1102: .A..AAA...AAAAA...e
                   1103: &lt;/script&gt;</pre>
                   1104: 
                   1105:    <p>The data in this case might be used by the script to generate
                   1106:    the map of a video game. The data doesn't have to be used that way,
                   1107:    though; maybe the map data is actually embedded in other parts of
                   1108:    the page's markup, and the data block here is just used by the
                   1109:    site's search engine to help users who are looking for particular
                   1110:    features in their game maps.</p>
                   1111: 
                   1112:   </div><div class="example">
                   1113: 
                   1114:    <p>The following sample shows how a script element can be used to
                   1115:    define a function that is then used by other parts of the
1.50      mike     1116:    document. It also shows how a <code><a href="#the-script-element">script</a></code> element can be
1.1       mike     1117:    used to invoke script while the document is being parsed, in this
                   1118:    case to initialize the form's output.</p>
                   1119: 
                   1120:    <pre>&lt;script&gt;
                   1121:  function calculate(form) {
                   1122:    var price = 52000;
                   1123:    if (form.elements.brakes.checked)
                   1124:      price += 1000;
                   1125:    if (form.elements.radio.checked)
                   1126:      price += 2500;
                   1127:    if (form.elements.turbo.checked)
                   1128:      price += 5000;
                   1129:    if (form.elements.sticker.checked)
                   1130:      price += 250;
                   1131:    form.elements.result.value = price;
                   1132:  }
                   1133: &lt;/script&gt;
1.52      mike     1134: &lt;form name="pricecalc" onsubmit="return false" onchange="calculate(this)"&gt;
1.1       mike     1135:  &lt;fieldset&gt;
                   1136:   &lt;legend&gt;Work out the price of your car&lt;/legend&gt;
                   1137:   &lt;p&gt;Base cost: &#163;52000.&lt;/p&gt;
                   1138:   &lt;p&gt;Select additional options:&lt;/p&gt;
1.52      mike     1139:   &lt;ul&gt;
1.1       mike     1140:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=brakes&gt; Ceramic brakes (&#163;1000)&lt;/label&gt;&lt;/li&gt;
                   1141:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=radio&gt; Satellite radio (&#163;2500)&lt;/label&gt;&lt;/li&gt;
                   1142:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=turbo&gt; Turbo charger (&#163;5000)&lt;/label&gt;&lt;/li&gt;
                   1143:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=sticker&gt; "XZ" sticker (&#163;250)&lt;/label&gt;&lt;/li&gt;
                   1144:   &lt;/ul&gt;
1.42      mike     1145:   &lt;p&gt;Total: &#163;&lt;output name=result&gt;&lt;/output&gt;&lt;/p&gt;
1.1       mike     1146:  &lt;/fieldset&gt;
                   1147:  &lt;script&gt;
1.42      mike     1148:   calculate(document.forms.pricecalc);
1.1       mike     1149:  &lt;/script&gt;
                   1150: &lt;/form&gt;</pre>
                   1151: 
1.15      mike     1152:   </div><h5 id="scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</h5><div class="impl">
1.1       mike     1153: 
                   1154:   <p>A user agent is said to <dfn id="support-the-scripting-language">support the scripting language</dfn>
                   1155:   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
                   1156:   case-insensitive</a> match for the <a href="infrastructure.html#mime-type">MIME type</a> string
                   1157:   of a scripting language that the user agent implements.</p>
                   1158: 
                   1159:   </div><p>The following lists some <a href="infrastructure.html#mime-type">MIME type</a> strings and the
                   1160:   languages to which they refer:</p><dl><dt>"<code>application/ecmascript</code>"</dt>
                   1161:    <dt>"<code>application/javascript</code>"</dt>
                   1162:    <dt>"<code>application/x-ecmascript</code>"</dt>
                   1163:    <dt>"<code>application/x-javascript</code>"</dt>
                   1164:    <dt>"<code>text/ecmascript</code>"</dt>
                   1165:    <dt>"<code>text/javascript</code>"</dt>
                   1166:    <dt>"<code>text/javascript1.0</code>"</dt>
                   1167:    <dt>"<code>text/javascript1.1</code>"</dt>
                   1168:    <dt>"<code>text/javascript1.2</code>"</dt>
                   1169:    <dt>"<code>text/javascript1.3</code>"</dt>
                   1170:    <dt>"<code>text/javascript1.4</code>"</dt>
                   1171:    <dt>"<code>text/javascript1.5</code>"</dt>
                   1172:    <dt>"<code>text/jscript</code>"</dt>
                   1173:    <dt>"<code>text/livescript</code>"</dt>
                   1174:    <dt>"<code>text/x-ecmascript</code>"</dt>
                   1175:    <dt>"<code>text/x-javascript</code>"</dt>
                   1176:    <dd>JavaScript. <a href="references.html#refsECMA262">[ECMA262]</a></dd>
                   1177: 
                   1178:    <dt>"<code>text/javascript;e4x=1</code>"</dt>
                   1179:    <dd>JavaScript with ECMAScript for XML. <a href="references.html#refsECMA357">[ECMA357]</a></dd>
                   1180: 
                   1181:   </dl><div class="impl">
                   1182: 
                   1183:   <p>User agents may support other <a href="infrastructure.html#mime-type" title="MIME type">MIME
                   1184:   types</a> and other languages.</p>
                   1185: 
1.48      mike     1186:   
1.1       mike     1187:   <p>When examining types to determine if they support the language,
                   1188:   user agents must not ignore unknown MIME parameters &#8212; types
                   1189:   with unknown parameters must be assumed to be unsupported. The <code title="">charset</code> parameter must be treated as an unknown
                   1190:   parameter for the purpose of comparing <a href="infrastructure.html#mime-type" title="MIME type">MIME
                   1191:   types</a> here.</p>
                   1192: 
1.50      mike     1193:   </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="#the-script-element">script</a></code> element
1.37      mike     1194:   must match the <code title="">script</code> production in the
                   1195:   following ABNF, the character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a></p><pre>script        = data1 *( escape [ script-start data3 ] "--&gt;" data1 ) [ escape ]
1.1       mike     1196: escape        = "&lt;!--" data2 *( script-start data3 script-end data2 )
                   1197: 
                   1198: data1         = &lt;any string that doesn't contain a substring that matches not-data1&gt;
1.48      mike     1199: not-data1     = "&lt;!--"             
1.1       mike     1200: 
                   1201: data2         = &lt;any string that doesn't contain a substring that matches not-data2&gt;
1.48      mike     1202: not-data2     = script-start / "--&gt;"  
1.1       mike     1203: 
                   1204: data3         = &lt;any string that doesn't contain a substring that matches not-data3&gt;
                   1205: not-data3     = script-end / "--&gt;"
                   1206: 
                   1207: script-start  = lt       s c r i p t tag-end
                   1208: script-end    = lt slash s c r i p t tag-end
                   1209: 
                   1210: lt            =  %x003C ; U+003C LESS-THAN SIGN character (&lt;)
                   1211: slash         =  %x002F ; U+002F SOLIDUS character (/)
                   1212: 
                   1213: s             =  %x0053 ; U+0053 LATIN CAPITAL LETTER S
                   1214: s             =/ %x0073 ; U+0073 LATIN SMALL LETTER S
                   1215: c             =  %x0043 ; U+0043 LATIN CAPITAL LETTER C
                   1216: c             =/ %x0063 ; U+0063 LATIN SMALL LETTER C
                   1217: r             =  %x0052 ; U+0052 LATIN CAPITAL LETTER R
                   1218: r             =/ %x0072 ; U+0072 LATIN SMALL LETTER R
                   1219: i             =  %x0049 ; U+0049 LATIN CAPITAL LETTER I
                   1220: i             =/ %x0069 ; U+0069 LATIN SMALL LETTER I
                   1221: p             =  %x0050 ; U+0050 LATIN CAPITAL LETTER P
                   1222: p             =/ %x0070 ; U+0070 LATIN SMALL LETTER P
                   1223: t             =  %x0054 ; U+0054 LATIN CAPITAL LETTER T
                   1224: t             =/ %x0074 ; U+0074 LATIN SMALL LETTER T
                   1225: 
1.53      mike     1226: tag-end       =  %x0009 ; U+0009 CHARACTER TABULATION (tab)
1.1       mike     1227: tag-end       =/ %x000A ; U+000A LINE FEED (LF)
                   1228: tag-end       =/ %x000C ; U+000C FORM FEED (FF)
                   1229: tag-end       =/ %x0020 ; U+0020 SPACE
                   1230: tag-end       =/ %x002F ; U+002F SOLIDUS (/)
1.50      mike     1231: tag-end       =/ %x003E ; U+003E GREATER-THAN SIGN (&gt;)</pre><p>When a <code><a href="#the-script-element">script</a></code> element contains <a href="#inline-documentation-for-external-scripts">script
1.1       mike     1232:   documentation</a>, there are further restrictions on the contents
1.50      mike     1233:   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="#the-script-element">script</a></code> element's <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is specified, then the
                   1234:   contents of the <code><a href="#the-script-element">script</a></code> element, if any, must be such
1.1       mike     1235:   that the value of the <code title="dom-script-text"><a href="#dom-script-text">text</a></code> IDL
                   1236:   attribute, which is derived from the element's contents, matches the
                   1237:   <code title="">documentation</code> production in the following
                   1238:   ABNF, the character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a></p><pre>documentation = *( *( space / tab / comment ) [ line-comment ] newline )
                   1239: comment       = slash star *( not-star / star not-slash ) 1*star slash
                   1240: line-comment  = slash slash *not-newline
                   1241: 
                   1242: ; characters
1.53      mike     1243: tab           = %x0009 ; U+0009 CHARACTER TABULATION (tab)
1.1       mike     1244: newline       = %x000A ; U+000A LINE FEED (LF)
                   1245: space         = %x0020 ; U+0020 SPACE
                   1246: star          = %x002A ; U+002A ASTERISK (*)
                   1247: slash         = %x002F ; U+002F SOLIDUS (/)
                   1248: not-newline   = %x0000-0009 / %x000B-10FFFF
                   1249:                 ; a Unicode character other than U+000A LINE FEED (LF)
                   1250: not-star      = %x0000-0029 / %x002B-10FFFF
                   1251:                 ; a Unicode character other than U+002A ASTERISK (*)
                   1252: not-slash     = %x0000-002E / %x0030-10FFFF
                   1253:                 ; a Unicode character other than U+002F SOLIDUS (/)</pre><p class="note">This corresponds to putting the contents of the
                   1254:   element in JavaScript comments.</p><p class="note">This requirement is in addition to the earlier
1.50      mike     1255:   restrictions on the syntax of contents of <code><a href="#the-script-element">script</a></code>
1.1       mike     1256:   elements.</p><div class="example">
                   1257: 
                   1258:    <p>This allows authors to include documentation, such as license
                   1259:    information or API information, inside their documents while still
                   1260:    referring to external script files. The syntax is constrained so
                   1261:    that authors don't accidentally include what looks like valid
                   1262:    script while also providing a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute.</p>
                   1263: 
                   1264:    <pre>&lt;script src="cool-effects.js"&gt;
                   1265:  // create new instances using:
                   1266:  //    var e = new Effect();
                   1267:  // start the effect using .play, stop using .stop:
                   1268:  //    e.play();
                   1269:  //    e.stop();
                   1270: &lt;/script&gt;</pre>
                   1271: 
1.49      mike     1272:   </div><div class="impl">
                   1273: 
1.50      mike     1274:   <h5 id="scriptTagXSLT"><span class="secno">4.3.1.4 </span>Interaction of <code><a href="#the-script-element">script</a></code> elements and XSLT</h5>
1.49      mike     1275: 
                   1276:   <p><i>This section is non-normative.</i></p>
                   1277: 
                   1278:   <p>This specification does not define how XSLT interacts with the
1.50      mike     1279:   <code><a href="#the-script-element">script</a></code> element (or, indeed, how XSLT processing
1.49      mike     1280:   triggers the <a href="the-end.html#stop-parsing">stop parsing</a> steps, how it interacts with
                   1281:   the <a href="history.html#navigate" title="navigate">navigation</a> algorithm, or how it
                   1282:   fits in with the <a href="webappapis.html#event-loop">event loop</a>). However, in the absence
                   1283:   of another specification actually defining this, here are some
                   1284:   guidelines for implementors, based on existing implementations:</p>
                   1285: 
                   1286:   <ul><li><p>When an XSLT transformation program is triggered by an <code title="">&lt;?xml-stylesheet?&gt;</code> processing instruction and
                   1287:    the browser implements a direct-to-DOM transformation,
1.50      mike     1288:    <code><a href="#the-script-element">script</a></code> elements created by the XSLT processor need to
1.49      mike     1289:    be marked <a href="#parser-inserted">"parser-inserted"</a> and run in document order
                   1290:    (modulo scripts marked <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code>
                   1291:    or <code title="attr-script-async"><a href="#attr-script-async">async</a></code>), asynchronously
                   1292:    while the transformation is occurring.</p></li>
                   1293: 
                   1294:    <li><p>The <code title="dom-XSLTProcessor-transformToDocument">XSLTProcessor.transformToDocument()</code>
                   1295:    method adds elements to a <code><a href="infrastructure.html#document">Document</a></code> that is not in a
                   1296:    <a href="browsers.html#browsing-context">browsing context</a>, and, accordingly, any
1.50      mike     1297:    <code><a href="#the-script-element">script</a></code> elements they create need to have their
1.49      mike     1298:    <a href="#already-started">"already started"</a> flag set in the <a href="#prepare-a-script">prepare a
                   1299:    script</a> algorithm and never get executed (<a href="webappapis.html#concept-bc-noscript" title="concept-bc-noscript">scripting is disabled</a>). Such
1.50      mike     1300:    <code><a href="#the-script-element">script</a></code> elements still need to be marked
1.49      mike     1301:    <a href="#parser-inserted">"parser-inserted"</a>, though, such that their <code title="dom-script-async"><a href="#dom-script-async">async</a></code> IDL attribute will return
                   1302:    false in the absence of an <code title="attr-script-async"><a href="#attr-script-async">async</a></code> content attribute.</p></li>
                   1303: 
                   1304:    <li><p>The <code title="dom-XSLTProcessor-transformToFragment">XSLTProcessor.transformToFragment()</code>
                   1305:    method needs to create a fragment that is equivalent to one built
                   1306:    manually by creating the elements using <code title="dom-document-createElementNS"><a href="infrastructure.html#dom-document-createelementns">document.createElementNS()</a></code>.
1.50      mike     1307:    For instance, it needs to create <code><a href="#the-script-element">script</a></code> elements that
1.49      mike     1308:    aren't <a href="#parser-inserted">"parser-inserted"</a> and that don't have their
                   1309:    <a href="#already-started">"already started"</a> flag set, so that they will execute
                   1310:    when the fragment is inserted into a document.</p></li>
                   1311: 
                   1312:   </ul><p>The main distinction between the first two cases and the last
                   1313:   case is that the first two operate on <code><a href="infrastructure.html#document">Document</a></code>s and the
                   1314:   last operates on a fragment.</p>
                   1315: 
1.22      mike     1316:   </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     1317:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                   1318:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                   1319:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
1.16      mike     1320:    <dt>Contexts in which this element can be used:</dt>
1.50      mike     1321:    <dd>In a <code><a href="semantics.html#the-head-element">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>
1.1       mike     1322:    <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>
                   1323:    <dt>Content model:</dt>
1.50      mike     1324:    <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">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#the-meta-element">meta</a></code> elements.</dd>
                   1325:    <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">head</a></code> element: <a href="content-models.html#transparent">transparent</a>, but there must be no <code><a href="#the-noscript-element">noscript</a></code> element descendants.</dd>
1.1       mike     1326:    <dd>Otherwise: text that conforms to the requirements given in the prose.</dd>
                   1327:    <dt>Content attributes:</dt>
                   1328:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
                   1329:    <dt>DOM interface:</dt>
                   1330:    <dd>Uses <code><a href="elements.html#htmlelement">HTMLElement</a></code>.</dd>
                   1331:   </dl><p>The <code><a href="#the-noscript-element">noscript</a></code> element <a href="rendering.html#represents">represents</a> nothing
                   1332:   if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a>, and
                   1333:   <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
                   1334:   to present different markup to user agents that support scripting
                   1335:   and those that don't support scripting, by affecting how the
                   1336:   document is parsed.</p><p>When used in <a href="dom.html#html-documents">HTML documents</a>, the allowed content
1.50      mike     1337:   model is as follows:</p><dl><dt>In a <code><a href="semantics.html#the-head-element">head</a></code> element, if <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> for the
1.1       mike     1338:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1339: 
                   1340:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only
1.50      mike     1341:    <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#the-meta-element">meta</a></code>
1.1       mike     1342:    elements.</p></dd>
                   1343: 
1.50      mike     1344:    <dt>In a <code><a href="semantics.html#the-head-element">head</a></code> element, if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
1.1       mike     1345:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1346: 
                   1347:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
                   1348:    except that invoking the <a href="the-end.html#html-fragment-parsing-algorithm">HTML fragment parsing
1.48      mike     1349:    algorithm</a>  with
1.51      mike     1350:    the <code><a href="#the-noscript-element">noscript</a></code> element as the <var title="concept-frag-parse-context"><a href="the-end.html#concept-frag-parse-context">context</a></var> element and the
                   1351:    text contents as the <var title="">input</var> must result in a
                   1352:    list of nodes that consists only of <code><a href="semantics.html#the-link-element">link</a></code>,
                   1353:    <code><a href="semantics.html#the-style-element">style</a></code>, and <code><a href="semantics.html#the-meta-element">meta</a></code> elements that would be
                   1354:    conforming if they were children of the <code><a href="#the-noscript-element">noscript</a></code>
                   1355:    element, and no <a href="parsing.html#parse-error" title="parse error">parse
                   1356:    errors</a>.</p></dd>
1.1       mike     1357: 
1.50      mike     1358:    <dt>Outside of <code><a href="semantics.html#the-head-element">head</a></code> elements, if <a href="webappapis.html#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> for the
1.1       mike     1359:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1360: 
                   1361:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element's content model is
                   1362:    <a href="content-models.html#transparent">transparent</a>, with the additional restriction that a
                   1363:    <code><a href="#the-noscript-element">noscript</a></code> element must not have a <code><a href="#the-noscript-element">noscript</a></code>
                   1364:    element as an ancestor (that is, <code><a href="#the-noscript-element">noscript</a></code> can't be
                   1365:    nested).</p></dd>
                   1366: 
1.50      mike     1367:    <dt>Outside of <code><a href="semantics.html#the-head-element">head</a></code> elements, if <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
1.1       mike     1368:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                   1369: 
                   1370:    <dd>
                   1371: 
                   1372:     <p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
                   1373:     except that the text must be such that running the following
                   1374:     algorithm results in a conforming document with no
1.50      mike     1375:     <code><a href="#the-noscript-element">noscript</a></code> elements and no <code><a href="#the-script-element">script</a></code>
1.1       mike     1376:     elements, and such that no step in the algorithm causes an
                   1377:     <a href="parsing.html#html-parser">HTML parser</a> to flag a <a href="parsing.html#parse-error">parse error</a>:</p>
                   1378: 
1.50      mike     1379:     <ol><li>Remove every <code><a href="#the-script-element">script</a></code> element from the
1.1       mike     1380:      document.</li>
                   1381: 
                   1382:      <li>Make a list of every <code><a href="#the-noscript-element">noscript</a></code> element in the
                   1383:      document. For every <code><a href="#the-noscript-element">noscript</a></code> element in that list,
                   1384:      perform the following steps:
                   1385: 
                   1386:       <ol><li>Let the <var title="">parent element</var> be the parent
                   1387:        element of the <code><a href="#the-noscript-element">noscript</a></code> element.</li>
                   1388: 
                   1389:        <li>Take all the children of the <var title="">parent element</var>
                   1390:        that come before the <code><a href="#the-noscript-element">noscript</a></code> element, and call these
                   1391:        elements <var title="">the before children</var>.</li>
                   1392: 
                   1393:        <li>Take all the children of the <var title="">parent element</var>
                   1394:        that come <em>after</em> the <code><a href="#the-noscript-element">noscript</a></code> element, and
                   1395:        call these elements <var title="">the after children</var>.</li>
                   1396: 
                   1397:        <li>Let <var title="">s</var> be the concatenation of all the
                   1398:        <a href="infrastructure.html#text-node">text node</a> children of the <code><a href="#the-noscript-element">noscript</a></code>
                   1399:        element.</li>
                   1400: 
                   1401:        <li>Set the <code title="dom-innerHTML"><a href="apis-in-html-documents.html#dom-innerhtml">innerHTML</a></code>
                   1402:        attribute of the <var title="">parent element</var> to the value
                   1403:        of <var title="">s</var>. (This, as a side-effect, causes the
                   1404:        <code><a href="#the-noscript-element">noscript</a></code> element to be removed from the
                   1405:        document.)</li>
                   1406: 
                   1407:        <li>Insert <var title="">the before children</var> at the start of
                   1408:        the <var title="">parent element</var>, preserving their original
                   1409:        relative order.</li>
                   1410: 
                   1411:        <li>Insert <var title="">the after children</var> at the end of the
                   1412:        <var title="">parent element</var>, preserving their original
                   1413:        relative order.</li>
                   1414: 
                   1415:       </ol></li>
                   1416: 
                   1417:     </ol></dd>
                   1418: 
                   1419:   </dl><p class="note">All these contortions are required because, for
                   1420:   historical reasons, the <code><a href="#the-noscript-element">noscript</a></code> element is handled
                   1421:   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
                   1422:   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
                   1423:   documents</a>.</p><p class="note"><strong>The <code><a href="#the-noscript-element">noscript</a></code> element is only
                   1424:   effective in <a href="syntax.html#syntax">the HTML syntax</a>, it has no effect in
                   1425:   <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML syntax</a>.</strong></p><div class="impl">
                   1426: 
                   1427:   <p>The <code><a href="#the-noscript-element">noscript</a></code> element has no other requirements. In
                   1428:   particular, children of the <code><a href="#the-noscript-element">noscript</a></code> element are not
                   1429:   exempt from <a href="association-of-controls-and-forms.html#form-submission">form submission</a>, scripting, and so forth,
                   1430:   even when <a href="webappapis.html#concept-n-script" title="concept-n-script">scripting is enabled</a>
                   1431:   for the element.</p>
                   1432: 
                   1433:   </div><div class="example">
                   1434: 
                   1435:    <p>In the following example, a <code><a href="#the-noscript-element">noscript</a></code> element is
                   1436:    used to provide fallback for a script.</p>
                   1437: 
                   1438:    <pre>&lt;form action="calcSquare.php"&gt;
                   1439:  &lt;p&gt;
                   1440:   &lt;label for=x&gt;Number&lt;/label&gt;:
                   1441:   &lt;input id="x" name="x" type="number"&gt;
                   1442:  &lt;/p&gt;
                   1443:  &lt;script&gt;
                   1444:   var x = document.getElementById('x');
                   1445:   var output = document.createElement('p');
                   1446:   output.textContent = 'Type a number; it will be squared right then!';
                   1447:   x.form.appendChild(output);
                   1448:   x.form.onsubmit = function () { return false; }
                   1449:   x.oninput = function () {
                   1450:     var v = x.valueAsNumber;
                   1451:     output.textContent = v + ' squared is ' + v * v;
                   1452:   };
                   1453:  &lt;/script&gt;
                   1454:  &lt;noscript&gt;
                   1455:   &lt;input type=submit value="Calculate Square"&gt;
                   1456:  &lt;/noscript&gt;
                   1457: &lt;/form&gt;</pre>
                   1458: 
                   1459:    <p>When script is disabled, a button appears to do the calculation
                   1460:    on the server side. When script is enabled, the value is computed
                   1461:    on-the-fly instead.</p>
                   1462: 
                   1463:    <p>The <code><a href="#the-noscript-element">noscript</a></code> element is a blunt
                   1464:    instrument. Sometimes, scripts might be enabled, but for some
                   1465:    reason the page's script might fail. For this reason, it's
                   1466:    generally better to avoid using <code><a href="#the-noscript-element">noscript</a></code>, and to
                   1467:    instead design the script to change the page from being a
                   1468:    scriptless page to a scripted page on the fly, as in the next
                   1469:    example:</p>
                   1470: 
                   1471:    <pre>&lt;form action="calcSquare.php"&gt;
                   1472:  &lt;p&gt;
                   1473:   &lt;label for=x&gt;Number&lt;/label&gt;:
                   1474:   &lt;input id="x" name="x" type="number"&gt;
                   1475:  &lt;/p&gt;
                   1476:  <strong>&lt;input id="submit" type=submit value="Calculate Square"&gt;</strong>
                   1477:  &lt;script&gt;
                   1478:   var x = document.getElementById('x');
                   1479:   var output = document.createElement('p');
                   1480:   output.textContent = 'Type a number; it will be squared right then!';
                   1481:   x.form.appendChild(output);
                   1482:   x.form.onsubmit = function () { return false; }
                   1483:   x.oninput = function () {
                   1484:     var v = x.valueAsNumber;
                   1485:     output.textContent = v + ' squared is ' + v * v;
                   1486:   };
                   1487: <strong>  var submit = document.getElementById('submit');
                   1488:   submit.parentNode.removeChild(submit);</strong>
                   1489:  &lt;/script&gt;
                   1490: &lt;/form&gt;</pre>
                   1491: 
                   1492:    <p>The above technique is also useful in XHTML, since
                   1493:    <code><a href="#the-noscript-element">noscript</a></code> is not supported in <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML
                   1494:    syntax</a>.</p>
                   1495: 
                   1496:   </div></body></html>

Webmaster