jQuery 在 iframe 父级中访问 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11717856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
access div in iframe parent
提问by Andrew Morris
I have a page which contains an iframe to another page, what I am looking for is to click something inside the iframe, which can then access or more specifically hide a div in the parent. I know some JQuery but for some reason just sit there blankly at the code editor when I try to write it on my own
我有一个包含 iframe 到另一个页面的页面,我正在寻找的是单击 iframe 内的某些内容,然后可以访问或更具体地隐藏父级中的 div。我知道一些 JQuery,但出于某种原因,当我尝试自己编写它时,只是呆呆地坐在代码编辑器前
回答by ehmad11
try this in iframe:
在 iframe 中试试这个:
$('#DIVtobehidden', window.parent.document).hide();
回答by adeneo
回答by rekire
If both pages are on the same (sub)domain you should be able to access the parent window with:
如果两个页面都在同一个(子)域中,您应该能够通过以下方式访问父窗口:
window.parent.document.getElementById('divId')
Well this is without jQuery but should work
嗯,这没有 jQuery,但应该可以工作