[英]How to show source code of an html file rendered in iframe
I've include a file in my script via i frame. 我通过i frame在我的脚本中包含了一个文件。
<iframe id="iFrame" src="index2.html" frameborder="0" style="overflow: hidden; height: 100%; width: 100%; position: absolute;" height="100%" width="100%"></iframe>
Now i want to show the source code of index2.html in this file. 现在我想在此文件中显示index2.html的源代码。 How can i do this
我怎样才能做到这一点
You should be able to retrieve the innerHTML
via Javascript using the following line of code: 您应该能够使用以下代码行通过Javascript检索
innerHTML
:
var sourceCode = document.getElementById('iFrame').contentWindow.document.body.innerHTML
When using jQuery the following line of code should do the trick: 使用jQuery时,以下代码行应该可以解决问题:
var sourceCode = $('#iFrame').contents().find("body").html();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.