I'm working on new plugin in javascript that load an HTML page using an Ajax request, extract all the scripts from the page and then execute it once all the content has been loaded. To do this I'm trying something like that :
var scripts = '',
domResponse = $('<div/>').append(HTMLresponse
.replace(/<\s*script\s*([^>]*)>((.|\n)*)<\s*\/\s*script>/i, function($0,$1,$2){
scripts += $2;
return '';
}));
// Then I load the content and I execute scripts
When I try with a page containing a single script tag it works fine, but if I try with a page like :
<script>
// Some javascript
</script>
<!-- SOME HTML -->
<script>
// Another script
</script>
domResponse is empty and scripts contain the text between the first <script> and the last </script>.
Is there any solution to make it work properly ?