Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在iframe中定义top_Javascript_Html_Iframe - Fatal编程技术网

Javascript 在iframe中定义top

Javascript 在iframe中定义top,javascript,html,iframe,Javascript,Html,Iframe,我有这样一个“弗兰肯斯坦”代码: <body> <iframe src="ThirdPartyPage"> <... id="foo"> <iframe> ... top.document.getElementById(foo) ... </iframe> </iframe> </body> ... top.document.getEleme

我有这样一个“弗兰肯斯坦”代码:

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

...
top.document.getElementById(foo)
...
有没有一种方法可以告诉javascript,顶部不是我的代码,而是第三方页面


编辑:这里的问题不是如何获得“foo”。这里的问题是,第三方页面试图从顶部获取“foo”,但现在有了新的iframe,第三方页面中的顶部不再是。

您不能重写
top
,也不能使用
getElementById(foo)访问任何DOM元素
iframe
你不能重写
top
,也不能使用
getElementById(foo)
从你要找的
iframe
而不是window.top.

你要找的是window.top,而不是window.top.

getElementById(foo)在第三方页面的新iframe之前工作。但是对于新的iframe,现在顶部不同了,并且正在破坏代码。getElementById(foo)在新的iframe之前在第三方页面上工作。但是有了新的iframe,现在顶部不同了,并且正在破坏代码。我在问题中添加了一个“编辑”来澄清问题。我在问题中添加了一个“编辑”来澄清问题。告诉我们你需要做什么。您的代码和第三方代码是什么,或者您所说的第三方是什么意思,现在还不太清楚。请告诉我们您需要做什么。您的代码和第三方代码是什么,或者您所说的第三方是什么意思,现在还不是很清楚。
//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")