I'm using eval()
to execute all <script>
tags after total rewrite of a div (whose code is loaded via an XMLHttpRequest
):
var arr = document.getElementById('idOfDIV').getElementsByTagName('script');
for (var n = 0; n < arr.length; n++){
try {
eval(arr[n].innerHTML);
} catch(err) {
console.log(err);
}
}
It works well for inline-scripts, but has no effect on scripts like:
<script src="/path/to/externalScript.js"></script>
How come? Can I "force" the browser to load and execute also the external scripts?
NOTE: As I noted, the question may seems "strange", regarding the fact that eval()
executes a string as javascript. What I need to do, is the force the browser to load external scripts contained in "pasted" DOM, and execute them.