牛骨文教育服务平台(让学习变的简单)
博文笔记

利用sessionStorage判断页面关闭还是刷新

创建时间:2017-08-04 投稿人: 浏览次数:156
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);
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。