zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js 前进 后退 刷新

JS 刷新 后退 前进
2023-06-13 09:12:40 时间

大家好,又见面了,我是你们的朋友全栈君。

前进

<input type=button value=前进 οnclick="window.history.go(1)">
<input type=button value=前进 οnclick="window.history.forward()">

后退

<input type=button value=后退 οnclick="window.history.go(-1)">
<input type=button value=后退 οnclick="window.history.back()">

刷新

<input type=button value=刷新 οnclick="window.location.reload()">
<input type=button value=刷新 οnclick="window.history.go(0)">
<input type=button value=刷新 οnclick="window.location=location">
<input type=button value=刷新 οnclick="window.location.assign(location)">
<input type=button value=刷新 οnclick="window.location.replace(location)">

后退+刷新

<input type=button value=后退+刷新 οnclick="window.history.go(-1);window.location.reload()">

注:window.可不加

history.go() 说明

  • history.go(0) 参数为0,表示刷新;
  • history.go(1) 参数为正数,表示前进。数字是几,表示前进几页;
  • history.go(-1) 参数为负数,表示后退。数字是几,表示后退几页。

location.assign() 说明

location.assign(URL) 方法会加载URL指定的文档内容。 如果使用 后退 功能,则回退到加载前页面。

location.replace() 说明

location.replace(URL) 方法会加载URL指定的文档内容来替换当前页面内容。 如果使用 后退 功能,则无法回退到加载前页面。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164185.html原文链接:https://javaforall.cn