Help: appendChild and IE bug

M

monkeybug07

Im having a strange problem which I assume is an IE bug (since it
works in Mozilla).

I have a page that checks to see if a certain javascript file has been
referenced before calling any functions in it. If the file has not
been referenced, it adds the reference to the <head> element.

Here is the code:

<script type="text/javascript" language="JavaScript1.2">
if (window.myFunction == null) {

function dhtmlLoadScript(url)
{
var e = document.createElement("script");
e.src = url;
e.type="text/javascript";

document.getElementsByTagName("head")[0].appendChild(e);
}

dhtmlLoadScript("/javascript/adminFunctions.js");

if (window.myFunction == null) {
// IE will fall into here, Mozilla will not
alert("Javascript not loaded");
}

</script>


The strange part about this is that after the first message box
(whether it is an error or an alert) all calls to the functions in the
new javascript file work. It seems that a messagebox somehow
refreshes the DOM so that is sees the new element that has been
appended in the <head> element.


Has anyone had any experience with this? Or knows a work around?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top