js刷新页面得重新加载和页面的刷新
1、reload 方法,该方法强迫浏览器刷新当前页面。
语法:location.reload([bForceGet])
参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5(“刷新”)
2、 replace 方法,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL。
语法: location.replace(URL)
通常使用: location.reload() 或者是 history.go(0) 来做。
此方法类似客户端点F5刷新页面,所以页面method=”post”时,会出现”网页过期”的提示。
因为Session的安全保护机制。
当调用 location.reload() 方法时, aspx页面此时在服务端内存里已经存在, 因此必定是 IsPostback 的。
如果有这种应用: 需要重新加载该页面,也就是说期望页面能够在服务端重新被创建,期望是 Not IsPostback 的。
这里,location.replace() 就可以完成此任务。被replace的页面每次都在服务端重新生成。
代码: location.replace(location.href);
3、返回并刷新页面:
location.replace(document.referrer);
document.referrer //前一个页面的URL
不要用 history.go(-1),或 history.back();来返回并刷新页面,这两种方法不会刷新页面。
4、Javascript刷新页面的几种方法:
- 1,history.go(0)
- 2,location.reload()
- 3,location=location
- 4,location.assign(location)
- 5,document.execCommand(’Refresh’)
- 6,window.navigate(location)
- 7,location.replace(location)
- 8,document.URL=location.href
1,history.go(0)
2,location.reload()
3,location=location
4,location.assign(location)
5,document.execCommand('Refresh')
6,window.navigate(location)
7,location.replace(location)
8,document.URL=location.href
5、自动刷新页面的方法:
5.1、页面自动刷新:把如下代码加入区域中,其中20指每隔20秒刷新一次页面
- <meta http-equiv=“refresh” content=“20”>
<meta http-equiv="refresh" content="20">
5.2、页面自动跳转:把如下代码加入区域中,其中20指隔20秒后跳转到https://www.baidu.com页面
- <meta http-equiv=“refresh” content=“20;url=”https://www.baidu.com”>
- 1
<meta http-equiv="refresh" content="20;url="https://www.baidu.com">
1
5.3、页面自动刷新js版
- <script language=“JavaScript”>
- function myrefresh()
- {
- window.location.reload();
- }
- setTimeout(’myrefresh()’,1000); //指定1秒刷新一次
- </script>
<script language="JavaScript">
function myrefresh()
{window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
6、JS刷新框架的脚本语句
- //刷新包含该框架的页面用
- <script language=JavaScript>
- parent.location.reload();
- </script>
- //子窗口刷新父窗口
- <script language=JavaScript>
- self.opener.location.reload();
- </script>
- ( 或 <a href=”javascript:opener.location.reload()”>刷新</a> )
- //刷新另一个框架的页面用
- <script language=JavaScript>
- parent.另一FrameID.location.reload();
- </script>
//刷新包含该框架的页面用
<script language=JavaScript>parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )
//刷新另一个框架的页面用
<script language=JavaScript>parent.另一FrameID.location.reload();
</script>
如果想关闭窗口时刷新或想开窗时刷新,在中调用以下语句即可。
- <body οnlοad=“opener.location.reload()”> 开窗时刷新
- <body onUnload=”opener.location.reload()”> 关闭时刷新
- <script language=”javascript”>
- window.opener.document.location.reload()
- </script>
<body οnlοad="opener.location.reload()"> 开窗时刷新
<body onUnload="opener.location.reload()"> 关闭时刷新
<script language="javascript">
window.opener.document.location.reload()
</script>
例如:
下面以三个页面分别命名为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 name=top src=”top.html”>
- <frame name=bottom src=”bottom.html”>
- </frameset>
- </HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> frame </TITLE>
</HEAD>
<frameset rows="50%,50%">
<frame name=top src="top.html">
<frame name=bottom src="bottom.html">
</frameset>
</HTML>
现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句,哪个好用自己看着办了。
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” οnclick=“window.parent.frames[1].location.reload()”><br>
- <input type=button value=”刷新2” οnclick=“window.parent.frames.bottom.location.reload()”><br>
- <input type=button value=”刷新3” οnclick=“window.parent.frames[‘bottom’].location.reload()”><br>
- <input type=button value=”刷新4” οnclick=“window.parent.frames.item(1).location.reload()”><br>
- <input type=button value=”刷新5” οnclick=“window.parent.frames.item(‘bottom’).location.reload()”><br>
- <input type=button value=”刷新6” οnclick=“window.parent.bottom.location.reload()”><br>
- <input type=button value=”刷新7” οnclick=“window.parent[‘bottom’].location.reload()”><br>
- </BODY>
- </HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> top.html </TITLE>
</HEAD>
<BODY>
<input type=button value="刷新1" οnclick="window.parent.frames[1].location.reload()"><br>
<input type=button value="刷新2" οnclick="window.parent.frames.bottom.location.reload()"><br>
<input type=button value="刷新3" οnclick="window.parent.frames['bottom'].location.reload()"><br>
<input type=button value="刷新4" οnclick="window.parent.frames.item(1).location.reload()"><br>
<input type=button value="刷新5" οnclick="window.parent.frames.item('bottom').location.reload()"><br>
<input type=button value="刷新6" οnclick="window.parent.bottom.location.reload()"><br>
<input type=button value="刷新7" οnclick="window.parent['bottom'].location.reload()"><br>
</BODY>
</HTML>
下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。
- <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
- <HTML>
- <HEAD>
- <TITLE> bottom.html </TITLE>
- </HEAD>
- <BODY οnlοad=”alert(‘我被加载了!’)”>
- <h1>This is the content in bottom.html.</h1>
- </BODY>
- </HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> bottom.html </TITLE>
</HEAD>
<BODY οnlοad="alert('我被加载了!')">
<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.如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。
- 附:
- Javascript刷新页面的几种方法:
- 1 history.go(0)
- 2 location.reload()
- 3 location=location
- 4 location.assign(location)
- 5 document.execCommand(’Refresh’)
- 6 window.navigate(location)
- 7 location.replace(location)
- 8 document.URL=location.href
1.window指代的是当前页面,例如对于此例它指的是top.html页面。
2.parent指的是当前页面的父页面,也就是包含它的框架页面。例如对于此例它指的是framedemo.html。
3.frames是window对象,是一个数组。代表着该框架内所有子页面。
4.item是方法。返回数组里面的元素。
5.如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。
附:
Javascript刷新页面的几种方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
7、自动刷新页面
1.页面自动刷新:把如下代码加入区域中
- [javascript] view plain copy print ?
- <meta http-equiv=“refresh” content=“20”>
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次页面.
2.页面自动跳转:把如下代码加入区域中
http://www.jb51.net“>
其中20指隔20秒后跳转到http://www.jb51.net页面
3.页面自动刷新js版
- <script language=“JavaScript”>
- function myrefresh()
- {
- window.location.reload();
- }
- setTimeout(’myrefresh()’,1000); //指定1秒刷新一次
- </script>
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
8、java在写Servler,Action等程序时,要操作返回页面的话(如谈出了窗口,操作完成以后,关闭当前页面,刷新父页面)
- [javascript] view plain copy print ?
- 1 PrintWriter out = response.getWriter();
- 2 out.write(”<script type=\”text/javascript\”>”);
- 3 子窗口刷新父窗口
- 4 out.write(”self.opener.location.reload();”);
- 5 //关闭窗口
- 6 out.write(”window.opener=null;”);
- 7 out.write(”window.close();”);
- 8 out.write(”</script>”);
1 PrintWriter out = response.getWriter(); 2 out.write("<script type=\"text/javascript\">"); 3 子窗口刷新父窗口 4 out.write("self.opener.location.reload();"); 5 //关闭窗口 6 out.write("window.opener=null;"); 7 out.write("window.close();"); 8 out.write("</script>");
9、JS刷新框架的脚本语句
1.如何刷新包含该框架的页面用
- <script language=JavaScript>
- parent.location.reload();
- </script>
<script language=JavaScript>
parent.location.reload();
</script>
2.子窗口刷新父窗口
- <script language=JavaScript>
- self.opener.location.reload();
- </script>
<script language=JavaScript>
self.opener.location.reload();
</script>
3、如何刷新另一个框架的页面用 (上面的实例以说明了)
- 语句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();
- 1
语句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();
1
4、如果想关闭窗口时刷新或者想开窗时刷新的话,在中调用以下语句即可。
- <body οnlοad=“opener.location.reload()”>
<body οnlοad="opener.location.reload()">
开窗时刷新
- [javascript] view plain copy print ?
- <body onUnload=“opener.location.reload()”>
<body onUnload="opener.location.reload()">
关闭时刷新
- <script language=“javascript”>
- window.opener.document.location.reload()
- </script>
<script language="javascript">
window.opener.document.location.reload()
</script>
转载地址:http://www.jb51.net/article/14397.htm
</div>
js刷新页面得重新加载和页面的刷新相关推荐
- JS判断访问设备(userAgent)加载不同页面 JS判断客户端操作系统类型(platform)
//平台.设备和操作系统var system ={win : false,mac : false,xll : false};//检测平台var p = navigator.platform;syste ...
- html5上拉下拉刷新,APP 上拉加载,下拉刷新 介绍
开发APP时,很多时候都会用上,上拉加载数据,下拉刷新等功能,本文件介绍两种. 一种是原生APP自带的上拉加载,下拉刷新功能,一种是用JS 插件写的上拉加载,下拉刷新. 1.原生APP 的 上拉加载, ...
- javascript实现页面的重新加载和页面的刷新
1.reload 方法,该方法强迫浏览器刷新当前页面. 语法:location.reload([bForceGet]) 参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里 ...
- 前端 JS 如何在一个页面中局部加载其它页面的数据
一个页面很大,可以分成多个部分,先把小部分的 jsp 写好之后,再在主页面中通过 Struts 2 标签或 ajax 请求来引入其它的 jsp 显示信息. 通过 jQuery 函数来加载其它页面的数据 ...
- webview加载html页面闪烁,webview加载Html页面
webview的属性 //支持javascript web.getSettings().setJavaScriptEnabled(true); //不使用缓存 webSettings.setCache ...
- 页面滚动动态加载数据,页面下拉自动加载内容
$(window).scroll(function () {var scrollTop = $(this).scrollTop();var scrollHeight = $(document).hei ...
- 在父页面用Iframe加载子页面时,将父页面的title替换成子页面title
报告管理 转载于:https://www.cnblogs.com/maomojun/p/9667320.html
- DCloud-MUI:下拉刷新、上拉加载
ylbtech-DCloud-MUI:下拉刷新.上拉加载 1. 下拉刷新返回顶部 0. http://dev.dcloud.net.cn/mui/pulldown/ 1. 概述 为实现下拉刷新功能,大 ...
- better-scroll 上拉加载,下拉刷新(解决移动端长页面卡顿)
一.Better Scroll 滚动原理 1.下图能直观的表示better-scroll的滚动原理 2.html设置 <div class="wrapper"> < ...
最新文章
- 关于关闭浏览器Session就丢失的讨论
- 光伏“转化效率之王”IBC电池有多牛?
- fs.readfile 显示html,从fs.readFile获取数据
- LINQ 学习笔记8
- 监控数据库锁阻塞_机器连接数_警报日志的shell脚本 分享
- 横向色差测试(LCA)—imatest
- 统计通话次数和时间的软件_通话时间统计app下载-通话时间统计下载 2.2.2 安卓版 - 河东软件园...
- Revit二次开发-设置视图范围无限制
- CDR教程-海报中的立体星星怎么画
- POI实现超大数据的Excel的读写操作,支持Excel最大行数。
- ffmpeg MP4 提取 MP3文件
- 2021 CCF基于UEBA的用户上网异常行为分析baseline线上0.90
- 小编为您介绍留声机的古与今
- AI深度、机器学习数据集资源汇总
- 【论文阅读】Dense Passage Retrieval for Open-Domain Question Answering
- 神经网络四:Softmax以及与Sigmoid的关系
- 南加州大学计算机科学案例,南加州大学计算机科学硕士录取
- Codeforces Round #702 (Div. 3)——B
- 医疗检测机构能力建设指导原则
- 联想ghost重装系统_一键ghost,图文详解使用一键ghost怎么重装win7系统
热门文章
- 【Simapro软件教程】参数进行灵敏度分析
- python录制视频和声音_moviepy 视频编辑添加MP3没声音的问题
- 面向对象的程序设计C++课堂复盘总结 C语言复习+C++基础语法
- 32位系统的虚拟内存空间最大容量
- 河南计算机与科学研究生招生,2021年河南理工大学计算机科学与技术(081200)硕士研究生招生信息_考研招生计划和招生人数 - 学途吧...
- new和delete,malloc和free
- POJ 1001-Exponentiation(NYOJ 155 求高精度幂):大数问题
- ApiPost接口测试的用法之------Post
- DirectX12(D3D12)基础教程(四)——初识DirectXMath库、使用独立堆创建常量缓冲、理解管线状态对象、理解围栏同步
- 【HTTP】协议格式、请求