javascript - JavaScript 如何监听浏览器返回,或者清除历史堆栈?
问题描述
history.pushState({ title: 'return' }, null, document.URL)
window.addEventListener('popstate', this.goBack, false)
function goBack() {
history.pushState(null, null, document.URL)
location.href = 'https://www.baidu.com'
}
这种监控方式需要用户在进入页面时点击。
不点击怎么触发?
解决方案
推荐阅读
- python - 如何减小 PyCharm 的 content.dat.storageData 缓存的大小?
- c# - 在 Azure 中嵌入控制台应用程序和调度
- react-native - 我使用 react-native-popup-dialog 并收到一些警告
- reactjs - setState 挂钩未更新
- kotlin - 是否可以使用 sqldelight 从本地资源加载预填充的数据库
- php - 变量值未在函数中传递
- windows - 如何将命令从命令行参数推送到函数参数?
- c++ - 在 travis 中为 cmake 构建指定编译器版本
- c# - 如何从两个不同的 Telegram 服务器添加联系人?
- function - 在 R 脚本中调用函数