Javascript 当用户单击浏览器的“后退”按钮时,Chrome忽略历史记录更改 < P> >我想在历史的中间包含一个URL,用于浏览器的按钮返回到这个URL,而不是例如“ >:空白Page(第一次加载)。
我有这个功能:Javascript 当用户单击浏览器的“后退”按钮时,Chrome忽略历史记录更改 < P> >我想在历史的中间包含一个URL,用于浏览器的按钮返回到这个URL,而不是例如“ >:空白Page(第一次加载)。,javascript,google-chrome,Javascript,Google Chrome,我有这个功能: function updateHistory(url) { const currentURL = window.location.href; window.history.pushState({}, '', url); window.history.pushState({}, '', currentURL); } 在Firefox和Safari中可以完美地工作,但在Chrome浏览器中,要求用户至少单击一个元素来执行此更新 我试着监听popstate事件,但是Chr
function updateHistory(url) {
const currentURL = window.location.href;
window.history.pushState({}, '', url);
window.history.pushState({}, '', currentURL);
}
在Firefox和Safari中可以完美地工作,但在Chrome浏览器中,要求用户至少单击一个元素来执行此更新
我试着监听popstate
事件,但是Chrome没有检测到任何东西
window.addEventListener('popstate', () => {
window.location.href = url;
});
是否有人知道Chrome中的这种行为,并且知道我如何处理它?
提前非常感谢您抽出时间