父窗口从IFRAME访问元素 [英] Access elements of parent window from iframe
问题描述
我有一个页面,我们可以称之为parent.php。在这个页面我有一个提交表单的iframe和那个以外我有id为目标一个div。是否有可能在iframe提交表单,当成功刷新目标股利。说加载了新的一页到它的东西?
编辑: 目标DIV是在父页面,所以我的问题是basicly如果你可以让为例的iframe于母公司之外的jQuery的电话。以及如何会看?
编辑2: 所以,这是我的jQuery的code貌似现在。它是在的iframe页面。股利#target在parent.php
$(;的形式[名称= my_form])递交(函数(E){。
即preventDefault;
window.parent.document.getElementById('#目标');
$(#目标)。负载(mypage.php,函数(){
$('形式[名称= my_form])提交()。
});
})
我不知道如果脚本是活动引起的形式succcessfully提交,但没有任何反应的目标。
编辑3:
现在我试着从iframe中的链接调用父页面。而没有成功有两种
< A HREF =JavaScript的:window.parent.getElementById('#目标)的负载('mypage.php');>链接< / A>
我想问题可能是你没有发现,因为在你的电话的#你的元素来得到它:
window.parent.document.getElementById('#目标');
您只需要在#如果你正在使用jQuery。这里应该是:
window.parent.document.getElementById(目标);
I have a page we can call parent.php. In this page i have an iframe with a submit form and outside of that i have a div with the id "target". Is it possible to submit the form in the iframe and when success refresh the target div. Say load a new page into it or something?
Edit: The target div is in the parent page, so my question is basicly if you can make for an example a jquery call outside the iframe to the parent. And how that would look?
Edit 2: So this is how my jquery code looks like now. It is in the of the iframe page. the div #target is in the parent.php
$(;"form[name=my_form]").submit(function(e){
e.preventDefault;
window.parent.document.getElementById('#target');
$("#target").load("mypage.php", function() {
$('form[name=my_form]').submit();
});
})
I dont know if the script is active cause the form submits succcessfully but nothing happens to target.
Edit 3:
Now im trying to call the parent page from a link within the iframe. And no success there either
<a href="javascript:window.parent.getElementById('#target').load('mypage.php');">Link</a>
I think the problem may be that you are not finding your element because of the "#" in your call to get it:
window.parent.document.getElementById('#target');
You only need the # if you are using jquery. Here it should be:
window.parent.document.getElementById('target');
这篇关于父窗口从IFRAME访问元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!