PDA

View Full Version : [SOLVED] Strange createChild behavior in IE



winklerd
15 Oct 2010, 7:56 AM
Hello,

I have the following code which works under Firefox but not IE or Chrome.



var headElement = Ext.DomQuery.selectNode('head');

var jsObject = {
tag: 'script',
type: 'text/javascript',
src: '/path/to/new/file.js'
};
var el = Ext.get(headElement).createChild(jsObject);
Using IE's Developer Tools, I'm able to see what's going on but I don't know why. When I inspect el, it seems to be getting set to the current last child of the head element. As an example:


<head>
...
<SCRIPT type=text/javascript src="/path/to/existing/file.js"></SCRIPT>
</head>After executing the above code in IE, el.dom.src is "/path/to/existing/file.js", NOT "/path/to/new/file.js" as I would expect. In Firefox, it works as I would expect it to.

Anyone able to offer some insight?

EDIT: Oh, this is ext 3.2.1

winklerd
20 Oct 2010, 6:39 AM
Sorry to bump the post, but hoping someone might have some ideas on this.

Condor
20 Oct 2010, 6:48 AM
createChild will use the insertAdjacentHTML function to insert the <script> tag which is probably not supported.

You will have to do this by hand, e.g.

var script = document.createElement("script");
script.setAttribute("src", "/path/to/new/file.js");
script.setAttribute("type", "text/javascript");
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);

winklerd
20 Oct 2010, 10:22 AM
Thanks for the info, Condor. That turned out to be the case. Looks like insertAdjacentHTML has restrictions on script elements. Doesn't happen in Firefox because that method doesn't exist and createChild does it another way.

mschwartz
20 Oct 2010, 10:31 AM
createChild will use the insertAdjacentHTML function to insert the <script> tag which is probably not supported.

You will have to do this by hand, e.g.

var script = document.createElement("script");
script.setAttribute("src", "/path/to/new/file.js");
script.setAttribute("type", "text/javascript");
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);

I ran across this issue in a non-ExtJS application, and this is exactly the case. SCRIPT tags cannot have child nodes in IE.