利用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);
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。