从iFrame中获取元素 [英] Get element from within an iFrame
本文介绍了从iFrame中获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从< iframe>
?
推荐答案
var iframe = document.getElementById('iframeId');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
您可以更简单地写出:
You could more simply write:
var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
并返回第一个有效的内部文档。
and the first valid inner doc will be returned.
一旦获得了内部文档,就可以像访问当前页面上的任何元素一样访问其内部。 ( innerDoc.getElementById
...等)
Once you get the inner doc, you can just access its internals the same way as you would access any element on your current page. (innerDoc.getElementById
...etc.)
重要提示:该iframe在同一个域中,否则您无法访问其内部。这将是跨站点脚本。
IMPORTANT: Make sure that the iframe is on the same domain, otherwise you can't get access to its internals. That would be cross-site scripting.
这篇关于从iFrame中获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文