首页 > 解决方案 > 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'
}

这种监控方式需要用户在进入页面时点击。

不点击怎么触发?

标签: javascriptvue.jsbrowser-history

解决方案


推荐阅读