当前位置:网站首页>JS--popstate事件--使用/教程/实例
JS--popstate事件--使用/教程/实例
2022-08-09 22:08:00 【IT利刃出鞘】
原文网址:JS--popstate事件--使用/教程/实例_IT利刃出鞘的博客-CSDN博客
简介
说明
本文介绍JavaScript的popstate事件的用法。
官网网址
WindowEventHandlers.onpopstate - Web API 接口参考 | MDN
相关网址
JS--history--使用/教程/实例_IT利刃出鞘的博客-CSDN博客_js中history
概述
当history对象发生变化时,就会触发popState事件。通过event.state可以访问当前历史记录的状态对象的拷贝。
当网页加载时,各浏览器对popstate事件是否触发有不同的表现,Chrome 和 Safari会触发popstate事件,而Firefox不会。
会触发popstate事件的场景
- 用户点击浏览器的前进、后退按钮
- 代码中调用history.back() 、history.forward()、history.go()
- a 标签的锚点
不会触发popstate事件的场景
- 代码中调用pushState()、replaceState()
代码示例
window.onpopstate = function(event) {
console.log(event.state)
}
// 或者
window.addEventListener('popstate', function(event) {
console.log('state: ' + JSON.stringify(event.state));
});
边栏推荐
- Users should clearly know that quantitative trading is not a simple procedure
- What is the stability of the quantitative trading interface system?
- Arcgis工具箱无法使用,显示“XML包含错误“的解决方法
- What kind of mentality do you need to have when using the stock quantitative trading interface
- shader学习笔记(五)
- What are the basic steps to develop a quantitative trading strategy?
- 【LaTex】 Font “FandolSong-Regular“ does not contain requested(fontspec)Script “CJK“.如何抑制此种警告?
- 用户要清晰知道,量化交易并非简单的程序
- Qt 消息机制和事件
- typedef和#define的花里胡哨的用法
猜你喜欢
随机推荐
Linux 配置MySQL
使用股票量化交易接口需要具备怎么样的心态
typedef和#define的花里胡哨的用法
Sun Zhengyi lost 150 billion: it was expensive at the beginning
leetcode 39. 组合总和(完全背包问题)
Users should clearly know that quantitative trading is not a simple procedure
用户要清晰知道,量化交易并非简单的程序
反射机制篇
Leetcode 701. 二叉搜索树中的插入操作
深度学习100例 —— 循环神经网络(RNN)实现股票预测
Analyses the development status quo of stock trading
mysql 、pg 查询日期处理
mysql中的key是怎么用的,或者这个值有什么意义,如下图?
Flutter 绘制美不胜收的光影流动效果
leetcode:331. 验证二叉树的前序序列化
Common commands and technical function modules of Metasploit
leetcode 38. 外观数列
PyQt5: Getting Started Tutorial
Leetcode 530. 二叉搜索树的最小绝对差
xlrd 与 xlsxwritter 的基本操作