gpt4 book ai didi

javascript - 如何显示在 iframe 中呈现的 html 文件的源代码

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

我已通过 i 框架在脚本中包含一个文件。

    <iframe id="iFrame" src="index2.html" frameborder="0"  style="overflow:           hidden; height: 100%; width: 100%; position: absolute;" height="100%"    width="100%"></iframe>

现在我想在这个文件中显示index2.html的源代码。我怎样才能做到这一点

最佳答案

您应该能够使用以下代码行通过 Javascript 检索 innerHTML:

var sourceCode = document.getElementById('iFrame').contentWindow.document.body.innerHTML

当使用 jQuery 时,下面的代码行应该可以解决问题:

var sourceCode = $('#iFrame').contents().find("body").html();

关于javascript - 如何显示在 iframe 中呈现的 html 文件的源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41263026/

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