P
petermichaux
Hi,
My AJAX response is a bit of HTML that I insert into the DOM. I extract
the contents of the script elements in the response into an array
called aScripts. I then want to append these to an element so that the
scripts will actually execute. I am trying a variation on what Randy
Webb posted a few months ago.
function insertScripts(element, aScripts) {
if(typeof element == "string") {element =
document.getElementById(element);}
for (var i=0, t=aScripts.length; i<t; i++) {
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = aScripts;
element.appendChild(newScript);
//newScript.appendChild(document.createTextNode(aScripts));
//eval(aScripts);
}
};
If I uncomment the eval() line then the scripts actually do execute but
using eval() defeats the purpose of Randy's suggested solution. It
seems like the "text" property is non-standard.
Any way to rescue this bit of code?
Thank you,
Peter
My AJAX response is a bit of HTML that I insert into the DOM. I extract
the contents of the script elements in the response into an array
called aScripts. I then want to append these to an element so that the
scripts will actually execute. I am trying a variation on what Randy
Webb posted a few months ago.
function insertScripts(element, aScripts) {
if(typeof element == "string") {element =
document.getElementById(element);}
for (var i=0, t=aScripts.length; i<t; i++) {
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = aScripts;
element.appendChild(newScript);
//newScript.appendChild(document.createTextNode(aScripts));
//eval(aScripts);
}
};
If I uncomment the eval() line then the scripts actually do execute but
using eval() defeats the purpose of Randy's suggested solution. It
seems like the "text" property is non-standard.
Any way to rescue this bit of code?
Thank you,
Peter