2017-06-27 64 views
-1

如何从iframe中检索html代码?从iframe获取html

我尝试:

$('#iframe').innerHtml 
$('#iframe').contents() 

它不工作。

你有什么想法吗?

感谢

+2

的可能的复制[获取iframe中的内容为字符串(https://stackoverflow.com/questions/30116410/get-iframe-content-作为字符串) –

回答

4

由于跨来源资源共享(CORS)如果iframe是在同一个域,你只能访问内容。

下面的JavaScript会工作,如果是同一个域:

document.getElementById('iframe').contentWindow.document.body.innerHTML