2012-03-08 42 views
1

我有这样一个“怪人”代码:定义顶部IFRAME

<body> 
    <iframe src="ThirdPartyPage"> 
    <... id="foo"> 
    <iframe> 
     ... 
     top.document.getElementById(foo) 
     ... 
    </iframe> 
    </iframe> 
</body> 

有没有办法说,顶部是不是我的代码的JavaScript,但ThirdPartyPage呢?

编辑:这里的问题不是如何得到“富”。这里的问题在于第三方页面从顶部获取“foo”,但现在使用新的iframe,顶部不再是第三方页面。

+0

告诉我们你需要做什么。不清楚你的代码和第三方代码是什么,或者你的意思是第三方。 – Kaf 2012-03-08 16:38:28

回答

0

你不能在写top,你也无法从iframe

+0

getElementById(foo)在第三方页面周围的新iframe之前工作。但是,随着新的iframe,现在顶端是不同的,并打破了代码。 – 2012-03-08 16:27:42

1
//To get the parent node i.e. ThirdPartyPage 

document.getElementById("yourFrameId").parentNode 

//Also you could get the elements within the ThirdPartyPage as follows (returns an array of elements) 

document.getElementById("yourFrameId").parentNode.getElementsByTagName("tagName") 
+0

我已经为问题添加了一个“编辑”来澄清问题。 – 2012-03-08 16:28:45

0

您正在寻找window.parent访问使用getElementById(foo)任何DOM元素,而不是window.top。