用JS完成对opener或指定iframe页面的自动刷新

这篇博客介绍了如何使用JavaScript实现对opener窗口或指定iframe页面的自动刷新功能。通过设置onclick事件,分别展示了弹出新窗口关闭后使左侧框架页面刷新,以及点击按钮后使底部页面刷新的示例代码。此外,还提到了open.asp中关闭新窗口并刷新opener页面的技巧,强调该功能仅适用于IE6及以上版本。

这是一个很久以前的功能了。ajax流行时,被一些小朋友当成了ajax。其实都是js完成的。

其实,重点就是:你想刷新的页面的名字.location.reload(); 比如:打开者.父母.iframe名.location.reload();

框架页index.asp:

<html>

<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>

<frameset rows="64,*,19">
 <frame name="top" scrolling="no" noresize target="contents" src="top.asp">
 <frameset cols="150,*">
  <frame name="contents" target="main" src="left.asp">
  <frame name="main" src="right.asp">
 </frameset>
 <frame name="bottom" scrolling="no" noresize target="contents" src="bottom.asp">
 <noframes>
 <body>

 <p>此网页使用了框架,但您的浏览器不支持框架。</p>

 </body>
 </noframes>
</frameset>

</html>

top.asp:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<base target="contents">
</head>

<body>
<%=time()%>
</body>

</html>

leftp.asp:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 4</title>
<base target="main">
</head>

<body>
<%=time()%>
</body>

</html>

right.asp:(关键在这里)

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>right</title>
</head>

<body>
  <form method="POST">
 <p align="center">
 <input type="button" value="弹出新窗口(Opener),新窗口关闭后左侧框架页面自动刷新" name="B1" onclick="javascript:window.open('open.asp')"><br>
&nbsp;<input type="button" value="框架,点击后,底部的页面自动刷新" name="B2" onclick="javascript:parent.frames('bottom').document.location.reload();"><%=time()%><br>
 以上功能仅适用于IE6或以上</p>
</form>
</body>

</html>

bottom.asp:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 3</title>
<base target="contents">
</head>

<body>
<%=time()%>
</body>

</html>

open.asp:关键在这里,不能加入“window.opener = null”,否则无效

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>open</title>
</head>

<body>

<p align="center">
 <input type="button" value="点击后本窗口关闭,Opener的框架的左侧的页面自动刷新(仅适用于IE6以上)" name="B3" onclick="javascript:opener.parent.frames('contents').location.reload();window.close();"></p>
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值