使用jquery从iframe的父页面刷新div [英] Refresh div on parent page from iframe using jquery
问题描述
我使用fancybox的模式框与iFrame。从iFrame获得表格成功我使用下面的代码:
I'm using fancybox's modal box with an iFrame. On form success from the iFrame I'm using the code below:
<script type="text/javascript">
window.setTimeout('window.top.location.href = "/page.asp"; ',999);
</script>
<script language="javascript">
<!--
setTimeout("parent.$.fancybox.close();",1000)
//-->
</script>
这将关闭fancybox的模式框并刷新父页面。我希望使用Jquery的iFrame在父页面上刷新div。
This closes fancybox's modal box and refreshes the parent page. I want to target a div to refresh on the parent page from the iFrame using Jquery.
我希望在父页面上使用id =target的目标DIV刷新,而不是整个页面。
I want the target DIV on the parent page with the id="target" to refresh, NOT the entire page. How do I go about it using JQuery?
TIA
下面的代码示例
父页
Parent Page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
<body>
<div id="target">
content content
</div>
</body>
</html>
表单验证后的iframe页面
iFrame Page Upon Form Validation
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
<script type="text/javascript">
window.setTimeout('window.top.location.href = "/parent_page.asp"; ',999);
</script>
<script language="javascript">
<!--
setTimeout("parent.$.fancybox.close();",1000)
//-->
</script>
如何在父页面上创建函数来刷新div id =target并调用它来自iFrame。
How do I make a function on the parent page to refresh the div id="target" and call it from the iFrame. Right now, the entire parent page refreshes.
推荐答案
将第二个参数传递给jQuery,使用期望的范围
Pass the second parameter to jQuery, with the desired scope
替换 window.setTimeout('window.top.location.href =/page.asp;',999);
with这:
Replace window.setTimeout('window.top.location.href = "/page.asp"; ',999);
with this:
window.setTimeOut(function(){
$("#target", window.parent).load("/page.asp #target");
},999);
这篇关于使用jquery从iframe的父页面刷新div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!