javascript中的后退和刷新实现方法
作者:jingxian 时间:2023-08-23 09:36:45
<input type=button value=刷新 onclick="window.location.reload()">
<input type=button value=前进 onclick="window.history.Go(1)">
<input type=button value=后退 onclick="window.history.go(-1)">
<input type=button value=前进 onclick="window.history.forward()">
<input type=button value=后退 onclick="window.history.back()"> 后退+刷新<input type=button value=后退 onclick="window.history.go(-1);window.location.reload()">
在C# Web程序中,如为页面按钮写返回上一页代码
this.RegisterClientScriptBlock("E", "<script language=JavaScript>history.go(-2);</script>");
其中,history.go(-2),要写为-2,因在按钮事件触发前,已刷新一次页面,所以应是-2。
Response.Write("<script language=javascript>history.go(-2);</script>");
此处也要写为“-2”。跟直接写脚本的有所不同。history.back()是会上一页
i=1
history.go(i)去指定的某页
如果是history.go(0)那就是刷新这两个属于JS代码,相当于IE的前进、后退功能。
具体的用处就要看什么时候需要这个就用上。比如用户注册时的验证是后台验证,不符合要求的时候就可以用这个,可以最大限度保证用户少重复输入数据。
例如:载入页面:
function onLoadPage(){
if(event.srcElement.tagName=="SPAN"){
oFrame=top.window.middle.frames[2];
oTxt=event.srcElement.innerText;
switch(oTxt){
case "前 进":
oFrame.history.go(1);
case "后 退":
oFrame.history.back();
case "刷 新":
oFrame.location.reload();
}
}
}
打开一个jsp页面,肯定是用客户端脚本进行刷新了。
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
标签:javascript,后退,刷新
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pytorch 实现变量类型转换
2021-09-27 23:35:47
![](https://img.aspxhome.com/file/2023/0/133230_0s.png)
Django小白教程之Django用户注册与登录
2022-01-14 10:30:06
![](https://img.aspxhome.com/file/2023/1/95921_0s.png)
django框架实现模板中获取request 的各种信息示例
2023-08-31 05:16:41
![](https://img.aspxhome.com/file/2023/8/61738_0s.jpg)
Python 基于jwt实现认证机制流程解析
2022-07-15 00:25:30
PHP crc32()函数讲解
2023-06-10 00:34:45
![](https://img.aspxhome.com/file/2023/1/55391_0s.png)
Python 经典贪心算法之Prim算法案例详解
2024-01-01 18:18:27
![](https://img.aspxhome.com/file/2023/2/79482_0s.png)
pytorch 如何使用amp进行混合精度训练
2023-12-25 13:35:02
![](https://img.aspxhome.com/file/2023/0/88960_0s.jpg)
FF和IE之间7个JavaScript的差异[译]
2009-05-04 18:19:00
django实现同一个ip十分钟内只能注册一次的实例
2021-03-07 03:13:37
详解Python语法之模块Module
2021-06-24 06:28:28
Python基础知识学习之类的继承
2022-09-02 15:41:05
ASP常用函数:IsBlank()
2008-09-28 13:21:00
PyTorch深度学习LSTM从input输入到Linear输出
2022-04-03 23:11:32
![](https://img.aspxhome.com/file/2023/4/114594_0s.png)
把pandas转换int型为str型的方法
2022-02-16 15:45:03
MySql如何实现远程登录MySql数据库过程解析
2024-01-28 06:47:51
![](https://img.aspxhome.com/file/2023/1/95611_0s.png)
Oracle计算时间差常用函数
2024-01-22 11:08:32
python自动识别文本编码格式代码
2024-01-02 06:29:50
约瑟夫问题的Python和C++求解方法
2023-12-05 15:09:28
Pytorch BertModel的使用说明
2023-06-28 09:30:37
Python3连接Mysql8.0遇到的问题及处理步骤
2024-01-20 13:06:46
![](https://img.aspxhome.com/file/2023/4/99304_0s.png)