gpt4 book ai didi

javascript - 将脚本插入到加载的 iframe 中

转载 作者:行者123 更新时间:2023-12-03 11:17:31 30 4
gpt4 key购买 nike

我正在尝试将脚本插入到加载的 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;

}

正确的方法是什么?

最佳答案

试试这个:

<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>

关于javascript - 将脚本插入到加载的 iframe 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27270537/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com