portalguy123
Programmer
Hello Experts,
I am working on an AJAX application and I get a response back from the url which populates a div which has both HTML as well as JavaScript code , I need to extract the javascript from the response and set in the parent documnet's head tag so as to be able to acees the javascript in a global context.I use the following code to do so ,
But when I print the value of teh head element I get a null back , can you please let me know where I might be wrong.
Thanks in Advance!!
-Bob F.
I am working on an AJAX application and I get a response back from the url which populates a div which has both HTML as well as JavaScript code , I need to extract the javascript from the response and set in the parent documnet's head tag so as to be able to acees the javascript in a global context.I use the following code to do so ,
Code:
extractAndProcess = function(windowObj,n){
var re = /<script[\s\S]*?>([\s\S]*?)<\/scr/igm;
var result = '';
var match;
while (match = re.exec(responseString)) {
//document.write(match[1]);
//eval(match[1]);
result += match[1];
//alert ('The match is '+match[1]);
}
alert('The result is '+result);
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.id = 'uploadScript';
script.type = 'text/javascript';
[b]script.src = result;[/b]
head.appendChild(script);
alert('The set script is '+ document.getElementsByTagName("head")[0].value);
populateEmailids(windowObj,n);
}
But when I print the value of teh head element I get a null back , can you please let me know where I might be wrong.
Thanks in Advance!!
-Bob F.