Bug Tracker

Ticket #152 (closed bug: fixed)

Opened 8 years ago

Last modified 3 years ago

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

comment:1 Changed 8 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in SVN rev 245.

Note: See TracTickets for help on using tickets.