removeChild <script> before JavaScript executes
I have a local file that I am displaying in an iframe. I cannot alter the file (or any files included- css, script, etc). I need to remove all of the tags from the file. This is easy enough, but 开发者_Go百科I would like to remove them before the JavaScript inside them is executed. Simply doing:
window.onload = function(){
iframeHEAD.removeChild(iframeSCRIPT);
}
will remove the script tag, but not before the script tag's code is executed.
You can request the file with he XMLHttpRequest object, use a regular expression to remove the unwanted code from the string in the responseText, and than document.write the string into the iframe.
You can't do that. Browsers interpret <script>
content as soon as it's loaded.
精彩评论