VSP*_*VSP 13 html javascript iframe code-injection
我们需要在iframe中添加一个javascript元素(它在同一个web /域中,因此不会附加安全问题).我们得到了它的工作,但不知道如何填写其标签之间的脚本内容...你会怎么做?
var iframe = document.getElementById('iframeX');
var iframedocument = iframe.contentWindow.document;
var script = iframedocument.createElement('script');
script.setAttribute('type', 'text/javascript');
script.innerText = 'alert(\'hello\')'; //this doesnt work
script.value= 'alert(\'hello\')'; //this doesnt work either
var head = iframedocument.getElementsByTagName("head")[0];
head.appendChild(script);
Run Code Online (Sandbox Code Playgroud)
iframe文档中的所需结果:
<head>
<script type="text/javascript" >
alert('hello');
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
Pra*_*man 14
你试过了吗:
script.setAttribute('type', 'text/javascript');
script.innerHTML = 'alert(\'hello\')';
Run Code Online (Sandbox Code Playgroud)