[whatwg] When do scripts execute? (4.3.1)
lists.whatwg at stakface.com
Thu Jan 15 07:48:30 PST 2009
I have a question about when scripts execute. From my reading of section 4.3.1 it seems like if script elements are created and added to the DOM via DOM operations, then they should NOT be marked as parser-inserted, and should get run immediately (assuming no defer/async stuff). However, a page that I constructed to test this (below) fails in FF, Opera, and Safari (didn't test IE). Am I misreading the spec, or does it not accurately reflect current behavior? I found  after poking through the archives a bit, and it's somewhat related, but doesn't address this issue directly.
var sn = document.createElement('script');
sn.appendChild( document.createTextNode( 'document.getElementById("r").firstChild.data = "PASS";' ) );
document.body.appendChild( sn ); // this runs the script and sets r's text to PASS (verifiable by alert)
sn = document.createElement( 'script' );
document.body.appendChild( sn ); // this *should* run an empty script block and do nothing
// the next line should have no effect since the script already ran
sn.appendChild( document.createTextNode( 'document.getElementById("r").firstChild.data = "FAIL";' ) );
// here r's text is FAIL. why?
More information about the whatwg