Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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
iframe中框架的jQuery/javascript上下文是什么?_Javascript_Jquery_Iframe_Frameset - Fatal编程技术网

iframe中框架的jQuery/javascript上下文是什么?

iframe中框架的jQuery/javascript上下文是什么?,javascript,jquery,iframe,frameset,Javascript,Jquery,Iframe,Frameset,让我先说一句。。。我已经引用了这个问题/答案,它似乎包含了一些线索,但我仍然错过了整个画面 本质上,索引页的结构如下 <html> <body> <div class="frames-wrap"> <iframe id="this-iframe" src="location.php"> </iframe> </div> </body> </html> 然后lo

让我先说一句。。。我已经引用了这个问题/答案,它似乎包含了一些线索,但我仍然错过了整个画面

本质上,索引页的结构如下

<html>
<body>
  <div class="frames-wrap">
      <iframe id="this-iframe" src="location.php">

      </iframe>
  </div>
</body>
</html>

然后location.php包含一个框架集(嗯,不是我的主意…),它有两个像这样设置的框架

<frameset cols="350,*">
  <frame src="search.php" id="frame_search" name="search"/>
  <frame src="edit.php" id="frame_edit" name="edit" />
</frameset>  

如果我想操纵索引页和这些元素之间的对象,我该怎么做


我一直认为上下文应该类似于
window.parent.frames[0]。document
。。。我还缺少什么?

我认为technicolorenvy的链接有答案,但是选择器有一个鲜为人知的第二个参数,您可以在其中设置上下文

大概是这样的:

var iframeDoc = document.getElementById('myIframe');
iframeDoc = (iframeDoc.contentWindow) ? iframeDoc.contentWindow : (iframeDoc.contentDocument.document) ? iframeDoc.contentDocument.document : iframeDoc.contentDocument;


// From the parent window
$('p', iframeDoc).html('Hello from parent');

为框架ID提供有效的JavaScript标识符会有所帮助,然后您可以使用诸如
window.top.this\u iframe.frame\u edit.document
之类的结构作为上下文。

前言:除非来自同一域,否则您将无法访问iframes内容

要在iframe中选择元素,可以使用如下jQuery调用

element = $("#this_iframe").contents().find("#frame_search")

关键是使用
contents()
功能。参见

这些都很有帮助。当我试图通过DOM中的iframe时,我一直在轰炸。这似乎是因为我的代码驻留在ready()方法中,但在激发$(document).ready()时,iframe中调用的框架集没有加载


感谢所有的帮助和反馈

也引用了这个,但我太新了,不能发布多个链接。这个问题可能会帮助你:(无耻的自我推销,因为这个问题最初是由我提出的)谢谢你的反馈!然而,这对我来说是爆炸。ID现在有下划线而不是下划线。如果我使用console.log查看“幕后”发生的事情,如果我记录window.top.this\u iframe.document或记录window.top.document.getElementById('this\u iframe'),它将返回一些信息,因此帧编辑id似乎没有被“看到”。有什么想法吗?啊,contents()真是太棒了,我没有意识到iframe提供的支持。。。谢谢