javacript实现关闭子窗口,刷新父窗口效果代码

来源:互联网 发布:推荐一本自学java的书 编辑:程序博客网 时间:2024/05/02 02:03
 

本文主要要实现的是点父窗口里的弹出新窗口按钮,将弹出新窗口,在新窗口里面有两个方法,一个是刷新本面,另一个是关闭本页,同时要刷新父窗口,以下例子有两个文件,其中a.htm为父页,b.htm为子页,代码如下(由于a.htm页内容不多,可能会刷新过快而没看到效果,你可以适当增加内容,以便查看效果!)

a.htm程序代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 <title>父窗口</title>  
</head>    
<body> 
  <span onclick="window.open('z.htm')" style="cursor:hand;">打开子窗口</span>  
</body> 
</html>  
b.htm 程序代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>子窗口</title>  
<script language="javascript">  
   function closethewindow()  
    {  
       var url="f.htm";//要刷新的窗口  
      opener.document.location=url;   window.close();  
    } 
</script>  
</head>    
<body> 
  <span onclick="closethewindow();" style="cursor:hand;">关闭子窗口,刷新父窗口</span><br />  
 <span onclick="javascript:window.location.reload();" style="cursor:hand;">刷新此窗口</span> 
 </body>  
</html>