我可以从iframe页面访问iframe的父元素吗? [英] Can I access to iframe 's parent's element from the iframe page
本文介绍了我可以从iframe页面访问iframe的父元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先在同一个域下的两个页面
First the two page in under the same domain
在父页面.htm我只有元素输入#test
,
In the parent page.htm I have only a element like input#test
,
然后我在child.html中设置一个iframe,名为child.htm,在child.html中我写了js来查找父输入元素,例如
then I set a iframe in the parent page,called child.htm,in the child.html I write js to find the parent input element,like
var parent = window.self.top;
但我不能使用 var input = $(parent).find ('input #test')
在parent.htm中查找输入元素
but I can't use var input = $(parent).find('input#test')
to find the input element in parent.htm
我可以访问它吗?我怎样才能实现这一目标?
Can I access to it? How can I achieve that?
推荐答案
尝试
var input = $(window.self.top).contents().find('input#test');
或
var input = $(window.self.top.document).find('input#test');
这篇关于我可以从iframe页面访问iframe的父元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文