Ajax script execution in loadable content


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
6 views
Use this feature
function extractScripts(str) {
var reg = /((?:\|\|.)*?)<\\/script>/gi;
var results = str.match(reg);
if(results){
for (var i = 0; i < results.length; i++){
eval(results[i].replace(reg,\\'$1\\'));
}}}

But it does not handle loadable
function test(test){
alert(document.forms.data.elements.length);
}

But alerts, etc.
How do you implement?
by | 6 views

1 Answer

0 like 0 dislike
eval('function() {... }') will lead to what will be determined (and not execute) a function, which is written in the row. In your example this is the test function.
\r
So it can be called after eval:
\r
eval(results[i].replace(reg, '$1'));
test('habrahabr');
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Apr 10, 2019 by TechNOIR
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
28,014 users