[whatwg] HTML5 3.7.2 - document.write

On Thu, 4 Jun 2009, Kartikaya Gupta wrote:
>
> 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):
> 
> ---
> <HTML><HEAD>
> <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>');
>   document.close();
> }
> </script>
> </HEAD><BODY>
>  <button onclick="doDoc()">runDoc</button>
> </BODY></HTML>
> ---
> 
> Inside code.js:
> 
> ---
> document.write('<img src="testIMG.jpg" />');
> ---

This is (as far as parsing goes) equivalent to just loading a page that 
has "I am <script type="text/javascript" id=inner src=code.js></script>the 
<b>document</b>" as the contents. When you execute the first .write(), it 
starts a new parser.

However, the spec as written was a bit confusing. I've tried to clarify 
it by referencing the script nesting level explicitly.

Please let me know if this is not equivalent!

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Tuesday, 30 June 2009 21:07:29 UTC