Javascript and appending to the Head

puffpio

Golden Member
Dec 21, 1999
1,664
0
0
The following JS code is executed in the Body of a page, before the entire document has finished loading. The Head is already finished loading:

-----

var scriptelement = document.createElement("script");
scriptelement.setAttribute("type", "text/javascript");
scriptelement.setAttribute("charset", "utf-8");
scriptelement.setAttribute("src", "foobarauieboegia a real path here");

document.getElementsByTagName("head").item(0).appendChild(scriptelement);

------

this works fine in Chrome and FF, but is freezing IE.

document.getElementsByTagName("head").item(0) works..it's the appendChild that is causing IE to freeze. any ideas?
 

puffpio

Golden Member
Dec 21, 1999
1,664
0
0
hmm

i even tried
document.getElementById("agaegaeg").appendChild(scriptelement);

where agaegaeg is a known div already put in the page by the time the JS runs and it still hangs
 

puffpio

Golden Member
Dec 21, 1999
1,664
0
0
i fixed it
instead of using a appendChild to append a script element to the page, I added a document.writeln("scr"+"ipt>" etc etc);