W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2009

[whatwg] When do scripts execute? (4.3.1)

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 15 Jan 2009 15:09:18 -0800
Message-ID: <63df84f0901151509w5a164c06k7b2dc335db82ed38@mail.gmail.com>
On Thu, Jan 15, 2009 at 8:28 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
> Kartikaya Gupta wrote:
>>
>>  sn = document.createElement( 'script' );
>>  sn.setAttribute( 'type', 'text/javascript' );
>>  document.body.appendChild( sn );        // this *should* run an empty
>> script block and do nothing
>
> That looks like a bug in the spec to me.  Empty scripts with no @src are not
> executed when inserted into the DOM, and are executed if they ever become

At least in the mozilla implementation, though would be interested
what other implementations do. The reason was that I wanted to support
the following usage pattern:

s = document.createElement('script');
document.body.appendChild(s);
s.src = "http://foo/bar";

Note that in IE, you can set the src attribute any number of times and
every time it will download and execute the new script, even when the
old src value is the same as the new.

/ Jonas
Received on Thursday, 15 January 2009 15:09:18 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:09 UTC