Reputation: 147
I'm trying to add some script to my page creating an element with the script tag and then changing its innerHTML, it does work on Chrome and IE11 but its not working on IE8
when i change the innerHTML it just shows up like a label.
var contentScript = document.createElement("script");
contentScript.setAttribute("id", "contentSCRIPT");
contentScript.innerHTML = "alert('test');";
document.getElementById("main").appendChild(contentScript);
@Scott Mermelstein did this fiddle to help me out. http://jsfiddle.net/BjbAd/
does anyone know how to make it work on IE8? Keep in mind that i need to create the contentSCRIPT element, because I'll have to remove the script from the page after some things.
Upvotes: 1
Views: 1185
Reputation: 713
I think your issue is that innerHTML is not intended for use on script tags.
var contentScript = document.createElement("script");
contentScript.setAttribute("id", "contentSCRIPT");
contentScript.text = "alert('test');";
document.getElementById("main").appendChild(contentScript);
Upvotes: 2