我正在尝试将脚本插入到已加载的iframe中。没有任何运气试了这个;
document.write('<iframe src ="http://example.com/" width ="100" height ="100">
</iframe>');
document.getElementsByTagName('iframe')[0].onload = function() {
var curInnerHTML = document.body.innerHTML;
curInnerHTML = curInnerHTML.replace("</a>", "</a><scr" + "ipt>
document.write='Hi.......';</sc" + "ript>");
document.body.innerHTML = curInnerHTML;
}
这样做的正确方法是什么?
答案 0 :(得分:1)
试试这个:
<script>
document.write('<iframe src ="http://example.com/" width ="100" height ="100"></iframe>');
document.getElementsByTagName('iframe')[0].onload = function() {
var curInnerHTML = document.body.innerHTML;
curInnerHTML = curInnerHTML.replace("</a>", "</a>"+'<script>'+"document.write=Hi......."+"</sc"+"ript>");
document.body.innerHTML = curInnerHTML;
}
</script>