教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js刷新页面实例解析

js刷新页面实例解析

发布时间:2015-06-19   编辑:jiaochengji.com
本文介绍了js刷新页面的多种方法,js实现网页自动刷新、刷新当前页面的方法,有需要的朋友参考下。

例子,通过三个页面间的刷新,学习js刷新页面的方法。
三个页面分别命名为frame.html、top.html、bottom.html

frame.html 由上(top.html)下(bottom.html)两个页面组成。

代码:
 

复制代码 代码示例:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> frame </title>
</head><frameset rows="50%,50%">
<frame top.html">
<frame bottom.html">
</frameset>
</html>

现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句。
 

语句1. window.parent.frames[1].location.reload();
语句2. window.parent.frames.bottom.location.reload();
语句3. window.parent.frames["bottom"].location.reload();
语句4. window.parent.frames.item(1).location.reload();
语句5. window.parent.frames.item('bottom').location.reload();
语句6. window.parent.bottom.location.reload();
语句7. window.parent['bottom'].location.reload();

top.html 页面的代码如下:
 

复制代码 代码示例:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html><head><title> top.html </title></head>
<body>
<input type=button value="刷新1" ><br>
<input type=button value="刷新2" ><br>
<input type=button value="刷新3" bottom'].location.reload()"><br>
<input type=button value="刷新4" ><br>
<input type=button value="刷新5" bottom').location.reload()"><br>
<input type=button value="刷新6" ><br>
<input type=button value="刷新7" bottom'].location.reload()"><br>
</body>
</html>

下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。
bottom.html 页面:
 

复制代码 代码示例:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html><head><title> bottom.html </title></head>
<body 我被加载了!')">
<h1>this is the content in bottom.html.</h1>
</body>
</html>

解释:
1,window指代的是当前页面,例如对于此例它指的是top.html页面。
2,parent指的是当前页面的父页面,也就是包含它的框架页面。例如对于此例它指的是framedemo.html。
3,frames是window对象,是一个数组。代表着该框架内所有子页面。
4,item是方法。返回数组里面的元素。
5,如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。

附,自动刷新页面的方法:
1,页面自动刷新:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次页面

3,页面自动刷新js版
 

复制代码 代码示例:
<script language="javascript">
function myrefresh()
{
   window.location.reload();
}
settimeout('myrefresh()',1000); //指定1秒刷新一次
</script>

asp.net如何输出刷新父窗口脚本语句
 

复制代码 代码示例:
1,this.response.write("<script>opener.location.reload();</script>"); 
2,this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");  
3,response.write("<script language=javascript>opener.window.navigate(''你要刷新的页.asp'');</script>")

4,js刷新框架的脚本语句
 

复制代码 代码示例:

//如何刷新包含该框架的页面用  
<script language=javascript>
   parent.location.reload();
</script>  

//子窗口刷新父窗口
<script language=javascript>
    self.opener.location.reload();
</script>
( 或 <a href="">刷新</a>   )

//如何刷新另一个框架的页面用  
<script language=javascript>
   parent.另一frameid.location.reload();
</script>

您可能感兴趣的文章:
js刷新页面实例解析
js自动刷新当前页面方法详解
js控制网页自动刷新 刷新一次停止刷新
网页页面自动刷新三种方法
js刷新页面几种方法小结
js返回上一页并刷新多种方法举例
js定时刷新页面与跳转页面多种方法
Js 取得当前页面的URL网址参数
js自动刷新页面代码汇总
js返回上一页并刷新的多种方法

关键词: 刷新页面   
[关闭]
~ ~