获取iFrame中的所有元素
问题描述:
如何获取iFrame中的所有元素?我使用一些JavaScript代码在这里,但我不知道接下来我做什么,以及如何获取里面的所有元素中的iframe:获取iFrame中的所有元素
<iframe id="uploads" src="https://jsfiddle.net/mekwall/up4nu/"></iframe>
var iframe = document.getElementById('uploads');
var innerDoc = iframe.contentDocument;
我使用contentDocument
这是只给出<html><body></body></html>
答
你好,这是你的代码在jsfiddle中执行。 它在控制台中显示错误。
其中的原因错误就是这里所说的:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied
有关详细信息:https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
综述:您不能访问iframe的内容如果它来自不同的域。
您无法使用Javascript读取其他域的内容。 –