Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.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访问和更改父页面(使用jquery)_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript 从iframe访问和更改父页面(使用jquery)

Javascript 从iframe访问和更改父页面(使用jquery),javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,有没有办法从iframe访问到parrent页面(并更改parrent页面) $(parent.document).find("#selector").remove(); 在frame1.html中是,我想在单击时,将文本“单击的”添加到 $(parent.document).find("#selector").remove(); 谢谢。如果您的子页面(frame1.html)与父页面位于同一域中,您可以在子窗口中编写如下代码: $('#test1', parent.document)

有没有办法从iframe访问到parrent页面(并更改parrent页面)

$(parent.document).find("#selector").remove();

在frame1.html中是
,我想在单击
时,将文本“
单击的
”添加到

$(parent.document).find("#selector").remove();
谢谢。

如果您的子页面(frame1.html)与父页面位于同一域中,您可以在子窗口中编写如下代码:

 $('#test1', parent.document).html('<h1>clicked</h1>');
$(parent.document).find("#selector").remove();
因此,您的代码(frame1.html)可以如下所示:

 <a href="..." 
  onclick="$('#test1', parent.document).html('<h1>clicked</h1>');">click me</a>
$(parent.document).find("#selector").remove();


希望这能有所帮助。

重要注意事项:只有在父级和iframe都来自同一域的情况下,才能访问in和out iframe,否则由于同源策略,您无法访问

$(parent.document).find("#selector").remove();
请注意,这两个部分都有自己的文档。从iframe访问父对象非常简单

parent.document
$(parent.document).find("#selector").remove();
从父项来看,它是以下内容之一:

window.frames['iframeName']

(window.frames.length /*gives you the number of iframes in your document*/ )
$(parent.document).find("#selector").remove();
或者使用id引用它并执行以下操作(请注意支持!)

$(parent.document).find("#selector").remove();

下面的代码应该可以正常工作:

$(parent.document).find("#selector");
$(parent.document).find("#selector").remove();
选择器来自父文档以执行某些操作。例如:

$(parent.document).find("#selector").remove();

出于许多安全原因,这是不可能的。@ChristianVarga不完全正确:允许跨驻留在同一域中的元素执行此操作。