欢迎您访问橙子博客本站旨在为大家分享精彩的文章和优质的资源!

JS后退、前进、返回上一页和刷新代码

时间:2024-04-30 21:02热度:1150
‌本文给大家分享的是JS后退、前进、返回上一页并刷新的代码,非常实用值得收藏,下面就直接上代码吧。JS后退代码:window.history.go(-1) 可简写为: history.go(-1)window.history.back() 可简写为: history.back()JS前进代码:window.history.go(1) 可简写为: history.go(1)window.history.forward() 可简写为: history.forward()JS返回上一页并刷新代码:self.location=window.document.referrer 可简写为:

‌本文给大家分享的是JS后退、前进、返回上一页并刷新的代码,非常实用值得收藏,下面就直接上代码吧。

JS后退代码:

window.history.go(-1)      可简写为:   history.go(-1)
window.history.back()      可简写为:   history.back()

JS前进代码:

window.history.go(1)        可简写为:   history.go(1)
window.history.forward()    可简写为:   history.forward()

JS返回上一页并刷新代码:

self.location=window.document.referrer     可简写为:   self.location=document.referrer

JS刷新代码:

history.go(0)
location.reload()
location=location
location.assign(location)
document.execCommand('Refresh')
window.navigate(location)
location.replace(location)
document.URL=location.href

调用实例:

(1)按钮调用:

<input type="button" value="后退" onclick="window.history.go(-1)" />
<input type="button" value="返回上一页" onclick="history.back()" />
<input type="button" value="前进" onclick="window.history.go(1)" />
<input type="button" value="前进" onclick="window.history.forward()" />
<input type="button" value="返回上一页并刷新" onclick="self.location=window.document.referrer;" />
<input type="button" value="刷新" onclick="window.location.reload()" />

(2)链接调用:

<a href="javascript:history.go(-1);">后退</a>
<a href="javascript:" onclick="history.back()">返回上一页</a>
<a href="#" onclick="javascript:history.back();">返回上一步</a>
<a href="javascript:history.go(1);">前进</a>
<a href="#" onclick="history.forward();">前进</a>
<a href="javascript:" onclick="self.location=document.referrer;">返回上一页并刷新</a>
<a href="#" onclick="location.reload();">刷新</a>

以上就是JS后退、前进、返回上一页并刷新代码的全部内容。

相关标签: 后退前进刷新
打赏 :
分享 :
扫码支持扫码支持

文章标题:JS后退、前进、返回上一页和刷新代码

文章链接:https://www.trnt.cn/Web/69.html

所有文章未经授权禁止转载、摘编、复制或建立镜像,违规转载法律必究。

本站部分内容来源于网络,仅供大家学习与参考,如有侵权,请联系站长邮箱:906080088@qq.com进行处理。