当前位置:网站首页>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));
});
边栏推荐
- 异常处理(try,catch,finally)
- Activiti7审批流
- Janus官方DEMO介绍
- shell学习
- leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
- Vmware中安装win7虚拟机以及相关简单知识
- R语言ggplot2可视化:使用ggpubr包的ggscatter函数可视化散点图、使用scale_x_continuous函数的breaks参数指定X轴的断点的个数(设置参数n)
- Good future, want to be a second new Oriental
- MySQL——JDBC
- 信息系统项目管理师---第十一章项目风险管理历年考题
猜你喜欢
月薪5K的运维小白如何成为月薪5W的高级架构师?
Chapter 15 HMM模型
leetcode:321. 拼接最大数
注意力引导网络用于视网膜图像分割
CV复习:softmax代码实现
(转)FreeType字体位图属性
【Burning】It's time to show your true strength!Understand the technical highlights of the 2022 Huawei Developer Competition in one article
OSG笔记:使用setFontResolution设置字体分辨率
Install win7 virtual machine in Vmware and related simple knowledge
Qt 消息机制和事件
随机推荐
setter与getter访问器属性——数据驱动显示
注意力引导网络用于视网膜图像分割
Postgresql源码(68)virtualxid锁的原理和应用场景
mysql 、pg 查询日期处理
A. Common Prefixes
torch.distributed多卡/多GPU/分布式DPP(二)——torch.distributed.all_reduce(reduce_mean)&barrier&控制进程执行顺序&随机数种子
leetcode 39. 组合总和(完全背包问题)
重装系统后新建文本文档打不开怎么办
leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
用户要清晰知道,量化交易并非简单的程序
量化交易接口系统有哪些稳定性?
信息系统项目管理师---第十一章项目风险管理历年考题
R语言拟合ARIMA模型并使用拟合模型进行预测推理:使用forecast函数计算ARIMA模型未来值(包含时间点、预测值、两个置信区间)
Analyze the Add() method in Fragment management from the source code
shell学习
R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义Y轴的轴标签文本(customize Y axis labels)
CV review: softmax code implementation
p5.js实现的炫酷星体旋转动画
全球不用交税的国家,为什么不交
JuiceFS 在多云存储架构中的应用 | 深势科技分享