是否可以使用iframe_id获取iframe文档?

时间:2009-05-20 10:16:09

标签: dom iframe

AFAIK,我可以通过window.frames ['frame_name']

实现这一目标

但如果我只知道frame_id,是否也可以获取内容?

你可以在这里试试:

http://maishudi.com/rte-light-read-only/index.html

btw,是否可以通过iframe_id获取位置属性?

我很久以前就试过但却失败了。

1 个答案:

答案 0 :(得分:1)

我认为应该这样做。它适用于(最新的)firefox,safari,camino和opera(mac)。
你应该做一些测试(特别是在IE中)

var iframeObj = document.getElementById("theIframeId");
var documentObj = iframeObj.contentWindow || iframeObj.contentDocument;
var location = documentObj.location.href; // I think this only works if
                                          // the content of the iframe comes 
                                          // from the same domain.