关于关闭子窗口后刷新父窗口的问题

时间:2021-07-28 23:52:33
父窗口用form提交数据到一个子窗口,
子窗口进行数据验证,
如何让子窗口数据验证完后关闭并刷新父窗口,
有人说用window.opener.location.href,
但我试了好久都不行,
请哪位高手帮忙下,
父窗口及子窗口用JS分别要怎么写

8 个解决方案

#1


window.navigate(window.location.href) 

#2


这位高手,还是不行呀,能不能具体说下在父窗口及子窗口分别要怎么写呀,
我是JS新手呀

#3


引用 1 楼 SeerMi 的回复:
window.navigate(window.location.href) 

这位高手,还是不行呀,能不能具体说下在父窗口及子窗口分别要怎么写呀, 
我是JS新手呀

#4


关键是在子窗口页面的onunload事件中增加对父窗口的刷新功能,其实只关子页面的问题,测试通过;

<script language="javascript" type="text/javascript">
function reshow()
{
window.opener.location.reload();
}
</script>

页面的onunload事件修改:
<body onUnload="javascrip:reshow();">
-----------------------------------------------------------------------
完成实验例子代码如下:


父页面:
-----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>父窗口</title>
</head>
<script language="javascript" type="text/javascript">
var i=0;
function add()
{
i+=1;
document.getElementById("num").innerHTML=i;
}
</script>
<body>
<p><b>FUNCTION:关闭子窗口时自动刷新父窗口</b></p>
<div id="num">记数变化0</div>
<input type="button" value="add" name="add" onClick="javascript:add();">
<br>
<a  target="_blank" href="index2.htm">sub index2</a>
</body>
</html>
-----------------------------------------------------------------------

子页面:
-----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>子窗口</title>
</head>
<script language="javascript" type="text/javascript">
function reshow()
{
window.opener.location.reload();
}
</script>
<body onUnload="javascrip:reshow();">
子窗口关闭时刷新父窗口
</body>
</html>
-----------------------------------------------------------------------
呵呵...有点分可以加不,想加点分^=^

#5


window.opener.reload()

#6


算了,一人一分吧。。

#7


我原来用过你类似的情况,window.opener.reload() 可以的啊

#8



window.parent.location.reload(); 


http://www.w3school.com.cn/htmldom/dom_obj_window.asp

#1


window.navigate(window.location.href) 

#2


这位高手,还是不行呀,能不能具体说下在父窗口及子窗口分别要怎么写呀,
我是JS新手呀

#3


引用 1 楼 SeerMi 的回复:
window.navigate(window.location.href) 

这位高手,还是不行呀,能不能具体说下在父窗口及子窗口分别要怎么写呀, 
我是JS新手呀

#4


关键是在子窗口页面的onunload事件中增加对父窗口的刷新功能,其实只关子页面的问题,测试通过;

<script language="javascript" type="text/javascript">
function reshow()
{
window.opener.location.reload();
}
</script>

页面的onunload事件修改:
<body onUnload="javascrip:reshow();">
-----------------------------------------------------------------------
完成实验例子代码如下:


父页面:
-----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>父窗口</title>
</head>
<script language="javascript" type="text/javascript">
var i=0;
function add()
{
i+=1;
document.getElementById("num").innerHTML=i;
}
</script>
<body>
<p><b>FUNCTION:关闭子窗口时自动刷新父窗口</b></p>
<div id="num">记数变化0</div>
<input type="button" value="add" name="add" onClick="javascript:add();">
<br>
<a  target="_blank" href="index2.htm">sub index2</a>
</body>
</html>
-----------------------------------------------------------------------

子页面:
-----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>子窗口</title>
</head>
<script language="javascript" type="text/javascript">
function reshow()
{
window.opener.location.reload();
}
</script>
<body onUnload="javascrip:reshow();">
子窗口关闭时刷新父窗口
</body>
</html>
-----------------------------------------------------------------------
呵呵...有点分可以加不,想加点分^=^

#5


window.opener.reload()

#6


算了,一人一分吧。。

#7


我原来用过你类似的情况,window.opener.reload() 可以的啊

#8



window.parent.location.reload(); 


http://www.w3school.com.cn/htmldom/dom_obj_window.asp