PDA

View Full Version : Help with DomHelper.append function



ljadrbln
27 Apr 2010, 6:05 PM
Hello,

I need to ask a little help with DomHelper object.
I want to create a tag script.



var t = Ext.DomHelper.append(Ext.getBody() , {
language: 'javascript',
tag: 'script',
type: 'text/javascript',
src : 'Index1.js'
});
alert(t);


In FF alert returned [Object HTMLScriptElement],
But in IE message is [Object HTMLDivElement].

ljadrbln
28 Apr 2010, 10:49 AM
Any ideas?

cnelissen
28 Apr 2010, 12:34 PM
There is a strange issue with IE when you insert script into the dom. IE treats script tags as NoScope element, similar to comments and style tags. Also, any scripts you inject must have defer set, don't ask me why. I tested this in IE and it works fine.



var t = Ext.DomHelper.insertHtml('beforeEnd', Ext.getBody().dom, '<input type="hidden"/>' + unescape('%3Cscript type="text/javascript" src="Index1.js" defer="defer"%3E%3C/script%3E'));


You could replace the hidden input with a div, or some other element, it just needs it for insertion to work.

With that said, it seems odd that you would need to inject a script tag in this way, why not just include it when you load the file?