[whatwg] HTML5 3.7.2 - document.write

Kartikaya Gupta lists.whatwg at stakface.com
Thu Jun 4 11:16:05 PDT 2009

I have a question about section 3.7.2. Under step 5, it says that it is considered a reentrant invocation of parser if the document.write() method was called from script executing inline. Does this include document.write() calls invoked from user actions (e.g. onclick)? I assume not, but I'm getting varying behavior from the major browsers for this test case (click on the button to run):

<script id="outter" type="text/javascript">
function doDoc() {
  document.write('I am <scr'+'ipt type="text/javascript" id=inner src=code.js></scr'+'ipt>the <b>document</b>');
 <button onclick="doDoc()">runDoc</button>

Inside code.js:

document.write('<img src="testIMG.jpg" />');

testIMG.jpg is some image.

Chrome2/Safari4beta, Firefox3: the image shows up in the middle of the sentence, where the script tag is. This seems to go with the interpretation that the document.write call is not reentrant.
Opera10: the image shows up at the end of the sentence, which goes with the interpretation that the document.write call *is* reentrant (and there's a missing step in the spec to run any pending external scripts at the end of section 3.7.2)
IE6: doesn't seem to run that nested script at all as far as I can tell, which seems to also go with the interpretation that it's not reentrant and there's no missing steps in the spec.

If my interpretation of the spec is correct, The Webkit/Gecko behavior is correct, and Opera/IE are incorrect. Thoughts?


More information about the whatwg mailing list