Ticket #152 (closed bug: fixed)
Events module leaves stray script element in IE
| Reported by: | henrah | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.0 |
| Component: | event | Version: | 1.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Matthias Miller's DOMReady hack creates a new script element using document.write(). After its onload event has fired, however, this element remains part of the DOM -- it will be discovered by $('script') or $('head>*'), for example.
Since this is a permanent modification of the DOM, scripts which rely on a particular order or number of elements will throw exceptions. Assumptions about the generated DOM are often unreliable anyway, but it is not hard to imagine a situation where scripts could be broken by this.
The bug is trivial to fix, however: the element just needs to delete itself once it has become unnecessary.
We can change this section: script.onreadystatechange = function() {
if ( this.readyState == "complete" )
jQuery.ready();
};
...to this: script.onreadystatechange = function() {
if ( this.readyState != "complete" ) return; this.parentNode.removeChild(this); jQuery.ready();
};
...and then the problem is solved.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Fixed in SVN rev 245.