我想在新标签页中打开链接时,通过返回按钮能够返回到referrer页面。
const referrer = document.referrer;
const redirect = (e) => {
if(e.state.goBack){
window.location.href = window.location.href;
}
}
const _location = window.location.href
history.replaceState({goBack: true}, null, referrer);
history.pushState({}, null, _location);
window.addEventListener('popstate', redirect);
在 MacBook 和 Android 的 Chrome/Firefox 中一切正常。但是在 iPhone/iPad 上却无法工作,它只会返回到自己。即使我在重定向函数中添加一个警报,当我在 iPad 的 Chrome 上点击后退按钮时也不会出现警报 :(
感觉在 iPad 上点击后退按钮不会触发重定向函数。