Is this possible?
I inserted a simple test snippet like this
<script type="text/javascript">//<![CDATA[
document.write('foo');
//]]></script>
but it does nothing. ( W3 schools suggest the use of CDATA here, but this did not help ).
To reiterate this snippet was written into the .innerHTML property of the body tag.
I’ve seen some mentions of eval() on google but not too sure if this is relevant or good practice?
Wrapping the code in eval like they do here at W3 has no effect.
Javascript is only executed on first read, not when it is dynamically inserted as such. You would have to use something like the
eval()function to execute the content of the actual script. You could also use DOM functions likegetObjectsByTagName()to grab the script tag, and get its contents from there.