For reasons too complicated to get into now, I have an ajax call that returns some dynamically created Javascript that I want to inject into my page. The following code works on Chrome, but not in IE:
var node = document.getElementsByTagName("head")[0] || document.body;
if (node)
{
var script = document.createElement("script");
script.type = "text/javascript";
//script.innerHTML = json.javascript;
var textnode = document.createTextNode(json.javascript);
script.appendChild(textnode);
node.appendChild(script);
}
In IE, I get "SCRIPT65535: Unexpected call to method or property access." As you can see from the commented out code, before I tried the textnode, I tried just inserting it with script.innerHTML. That also worked in Chrome, but in IE I got "SCRIPT600:Unknown runtime error".
Is there a way to stick some javascript into the DOM in IE?
And of course, as soon as I post this, I find http://www.phpied.com/dynamic-script-and-style-elements-in-ie/
var node = document.getElementsByTagName("head")[0] || document.body;
if (node)
{
var script = document.createElement("script");
script.type = "text/javascript";
script.text = json.javascript;
node.appendChild(script);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With