利用sessionStorage判断页面关闭还是刷新
if(sessionStorage.opened){
console.log("窗口是刷新页面,不是新打开")
}else{
console.log("窗口是新打开")
//如果获取到历史url,则重定向到历史地址
if(localStorage.history && localStorage.history != window.location.href ){
window.location.replace(localStorage.history);
}
}
sessionStorage.setItem("opened","true");
localStorage.setItem("history",location.href);
console.log("窗口是刷新页面,不是新打开")
}else{
console.log("窗口是新打开")
//如果获取到历史url,则重定向到历史地址
if(localStorage.history && localStorage.history != window.location.href ){
window.location.replace(localStorage.history);
}
}
sessionStorage.setItem("opened","true");
localStorage.setItem("history",location.href);
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。