DOMContentLoaded event fires before the dynamically added script tag loads

RESOLVED INVALID

Status

()

Firefox
General
RESOLVED INVALID
10 years ago
8 years ago

People

(Reporter: Jia zheng, Unassigned)

Tracking

2.0 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

10 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16

I am a web developer. I use createElement and appendChild function to add script tags dynamically in order to load other JavaScript files. I could not get data from those JavaScript file in the DOMContentLoaded event handler. But from firebug, the new added script tags are loaded. The same codes are applicable in Opera browser, so I think it might be a bug for Firefox.

Reproducible: Always

Steps to Reproduce:
1.Create a new HTML file and add the follow codes in a script tag.
var newScript = document.createElement("script");
newScript.type = "text/javascript";
newScript.src = "test.js";
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(newScript);

window.addEventListener("DOMContentLoaded", function()
{
    //myNumber is defined in test.js, but Firefox could not get this.
    //Opera can alert the correct data.
    alert(myNumber);  
}, false);
2. Create a new javascript file and put the follow codes in it and save it as test.js.
var myNumber = 100;
3. Open the HTML file in Firefox.
Actual Results:  
Firebug shows that "myNumber is not defined".

Expected Results:  
alert the 100 in the message box as Opera browser does.
(Reporter)

Updated

10 years ago
Version: unspecified → 2.0 Branch
This bug was reported on Firefox 2.x or older, which is no longer supported and will not be receiving any more updates. I strongly suggest that you update to Firefox 3.6.3 or later, update your plugins (flash, adobe, etc.), and retest in a new profile. If you still see the issue with the updated Firefox, please post here. Otherwise, please close as RESOLVED > WORKSFORME
http://www.mozilla.com
http://support.mozilla.com/kb/Managing+profiles
http://support.mozilla.com/kb/Safe+mode
No reply, INCOMPLETE. Please retest with Firefox 3.6.x or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → INCOMPLETE
Actually, this is just invalid.  DOMContentLoaded shouldn't wait on that script load.
Resolution: INCOMPLETE → INVALID
You need to log in before you can comment on or make changes to this bug.