从iFrame内获取所有元素

Get all element from within an iFrame

本文关键字:元素 获取 iFrame      更新时间:2023-09-26

如何在iFrame内获得所有元素?我在这里使用一些javascript代码,但我不知道我接下来要做什么,以及如何在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中执行的代码。控制台显示错误

见截图:http://prntscr.com/c54jts

出现错误的原因如下:

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的内容来自不同的域,则不能访问。