Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript's document.write Inline Script Execution Order
    primarykey
    data
    text
    <p>I have the following script, where the first and third <code>document.writeline</code> are static and <strong>the second is generated</strong>:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; document.write("&lt;script language='javascript' type='text/javascript' src='before.js'&gt;&lt;\/sc" + "ript&gt;"); document.write("&lt;script language='javascript' type='text/javascript'&gt;alert('during');&lt;\/sc" + "ript&gt;"); document.write("&lt;script language='javascript' type='text/javascript' src='after.js'&gt;&lt;\/sc" + "ript&gt;"); &lt;/script&gt; </code></pre> <p>Firefox and Chrome will display <em>before</em>, <em>during</em> and <em>after</em>, while Internet Explorer first shows <em>during</em> and only then does it show <em>before</em> and <em>after</em>.</p> <p>I've come across <a href="http://www.elctech.com/blog/nesting-document-write" rel="noreferrer">an article that states</a> that I'm not the first to encounter this, but that hardly makes me feel any better.</p> <p><strong>Does anyone know how I can set the order to be deterministic in all browsers, or hack IE to work like all the other, sane browsers do?</strong></p> <p><strong>Caveats</strong>: The code snippet is a very simple repro. It is generated on the server and the second script is the only thing that changes. It's a long script and the reason there are two scripts before and after it are so that the browser will cache them and the dynamic part of the code will be as small as possible. It may also appears many times in the same page with different generated code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload