我可以注射这样的药片:
iframe.contentWindow.action...但是,如果我想发送一个函数在iframe中声明,然后调用它呢?
例如:
function hello(){...}
iframe.contentWindow...基本上都是从iframe内部声明和调用hello?
为了澄清,hello的操作应该在iframe内执行。例如,如果我将document.getElementById("input").value="foo";放在hello中,然后在iframe中调用它,则更改应该在iframe内部而不是在父窗口中在input内生效。
发布于 2015-04-25 03:52:17
将脚本标记插入到框架的<head>部分,其中包含您的代码。脚本标记可以是外部脚本引用,也可以是内联脚本。为了进行注射,你必须是同一个来源。
var idoc = iframe.contentWindow.document;
var script = idoc.createElement("script");
script.textContent = 'document.getElementById("input").value="foo";'
idoc.getElementsByTagName("head")[0].appendChild(script);https://stackoverflow.com/questions/29860780
复制相似问题