使用JavaScript获取IFrame innerHTML [英] Get IFrame innerHTML using JavaScript
本文介绍了使用JavaScript获取IFrame innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码获取IFrame内部HTML。
I'm trying to get an IFrame inner HTML using below code.
<iframe src="http://www.msn.com"
width="100%" height="100%" marginwidth="0"
scrolling="no" frameborder="0" id="divInfo"
onreadystatechange="MyFunction(this);"></iframe>
JavaScript代码
JavaScript code is
function MyFunction(frameObj)
{
if (frameObj.readyState == "complete")
{
alert(frameObj.document.body.innerHTML);
}
}
但警报显示当前文档的html。当frmae就绪状态完成时,如何获得iframe的内部HTML。
But the alert shows me the html of current document. How can i get the inner HTML of iframe when the frmae ready state is complete.
如果我使用 alert(frameObj.contentWindow.document.body) .innerHTML);
它给了我拒绝访问错误。
If i use alert(frameObj.contentWindow.document.body.innerHTML);
it gives me Access is denied error.
提前致谢。
推荐答案
您无法读取< iframe>
的内容,该内容来自与其他域不同的域中的内容父页。
You can't read the contents of an <iframe>
that has content from a different domain than that of the parent page.
这篇关于使用JavaScript获取IFrame innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文