O
O
Oleg Karnaukhov2010-12-12 17:32:09
JavaScript
Oleg Karnaukhov, 2010-12-12 17:32:09

Ajax script execution in loadable content?

I use this function

function extractScripts(str) {<br/>
var reg = /&lt;script.*?&gt;((?:\n|\r|.)*?)&lt;\/script&gt;/gi;<br/>
var results = str.match(reg);<br/>
if(results){<br/>
for (var i = 0; i &lt; results.length; i++){<br/>
eval(results[i].replace(reg,\'$1\'));<br/>
}}}<br/>

But it does not process the downloadable
function test(test){<br/>
alert(document.forms.data.elements.length);<br/>
}

But alerts, etc. easily.
How can it be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antelle, 2010-12-12
@Antelle

eval('function() {… }') will cause the function that is written on the line to be defined (rather than executed). In your example, this would be the test function.
This is how it can be called after eval:
eval(results[i].replace(reg, '$1'));
test('habrahabr');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question