2013-02-18 11 views
7

this pageでテストしています。私は何が欠けているのか分かりません。JavaScriptを使用したフレームのドキュメントオブジェクトへのアクセス

// Two frames on the page 
> document.getElementsByTagName("frame").length 
2 

// Same domain, so no security restrictions 
> document.getElementsByTagName("frame")[0].src 
"http://www.quackit.com/html/templates/frames/menu_1.html" 
> window.location.href 
"http://www.quackit.com/html/templates/frames/frames_example_1.html" 

// Can't access the document 
> document.getElementsByTagName("frame")[0].document 
undefined 

これはうまくいくようですが、何が問題なのですか? IE8で動作する必要がありますが、私はChromeでもテストしています(最新の安定版)。

+3

実際に2013年にフレームを使用していますか、それともiFrameですか? – adeneo

+1

'document.getElementsByTagName(" frame ")[0] .contentDocument'はどうでしょうか? –

+0

'var frame = document.getElementsByTagName(" frame ")[0]; var frame_doc = frame.contentWindow.document || frame.contentDocument; 'フレームのドキュメントとして' frame_doc'を使用します。 – Ian

答えて

22

挨拶します以下のように、:

window.frames["frame_name"].document 

HTMLであった場合:

<frame name="frame_name">...</frame> 
0

あなたは、フレームは、あなたが変更したいとdはフレームの名前/ IDです

parent.frame.location.href = ... 

を使用することができます。しかし、その名前を使用して<frame>のドキュメントを取得することが可能である

var theFrame = document.getElementsByTagName("frame")[0]; 
var theFrameDocument = theFrame.contentDocument || theFrame.contentWindow.document; 
var button = theFrameDocument.getElementById("mybutton"); 

は、フレームの内容を取得するすべての周りの道はこのようなものとされて マルクに

関連する問題