网站首页 > 教程文章 正文
前面要加上jquery
比如<script src="style/jquery.min.js"></script>
监听事件
jQuery(document).ready(function($) {
if (window.history && window.history.pushState) {
$(window).on('popstate', function() {
var hashLocation = location.hash;
var hashSplit = hashLocation.split("#!/");
var hashName = hashSplit[1];
if (hashName !== '') {
var hash = window.location.hash;
if (hash === '') {
alert('後退按鈕點擊');
}
}
});
window.history.pushState('forward', null, './#forward');
}
});
History 对象
History 对象包含用户(在浏览器窗口中)访问过的 URL。
History 对象是 window 对象的一部分,可通过 window.history 属性对其进行访问。
history.pushState(state, title, url)
将当前URL和history.state加入到history中,并用新的state和URL替换当前。不会造成页面刷新。
state:与要跳转到的URL对应的状态信息。
title:不知道干啥用,传空字符串就行了。
url:要跳转到的URL地址,不能跨域。
- 上一篇: 从理解路由到实现一套Router(路由)
- 下一篇: 「网络安全」浅析跨域原理及如何实现跨域
猜你喜欢
- 2024-12-02 深入理解vue-router原理
- 2024-12-02 20道Vue常见面试题,你会几道?
- 2024-12-02 前端接口防止重复请求实现方案
- 2024-12-02 这些iframe跨域解决方案你需要了解一下,以后不应该再是你的盲区
- 2024-12-02 XSS讲解下(web安全入门11)
- 2024-12-02 2023近期前端面试遇到的题(前端初级)
- 2024-12-02 js基础面试题131-160道题目
- 2024-12-02 js中hash、hashchange事件
- 2024-12-02 IFRAME的各种经验总结
- 2024-12-02 通过 React Router V6 源码,掌握前端路由
- 最近发表
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- mybatis plus page (35)
- vue @scroll (38)
- 堆栈区别 (33)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)
- redis aof rdb 区别 (33)
- 302跳转 (33)
- http method (35)
- js array splice (33)