窗口

//挽留窗
        var url = window.location.href;
        if(!(url.indexOf("1.html") > -1)){
            if(url.indexOf("z.html") > -1){
                var backLag = inv.getCookie('z');
            }else if(url.indexOf("s.html") > -1){
                
                var backLag = inv.getCookie('s');
            }else if(url.indexOf("b.html") > -1){
                
                var backLag = inv.getCookie('b');
            }else if(url.indexOf("l.html") > -1){
                
                var backLag = inv.getCookie('l');
            }else if(url.indexOf("q.html") > -1){
                
                var backLag = inv.getCookie('q');
            }
            backLag ? backLag : backLag = true;
            if(backLag == true){
                inv.addEventBack();
            }
            
            $('.rym_btn').click(()=>{
                var url = window.location.href;
                if(url.indexOf("z.html") > -1){
                    inv.setCookie('z', false, "/");
                }else if(url.indexOf("hys.html") > -1){
                    inv.setCookie('s', false, "/");
                }else if(url.indexOf("b.html") > -1){
                    inv.setCookie('b', false, "/");
                }else if(url.indexOf("l.html") > -1){
                    inv.setCookie('l', false, "/");
                }else if(url.indexOf("q.html") > -1){
                    inv.setCookie('q', false, "/");
                }        
                backLag = false;
                inv.removeEventBack();
                window.addEventListener("popstate",function(){
                    window.history.back(window.history.back());
                }, false);
            })
            
            
        }
addBackKey : function(){  //显示挽留窗
    $('.lag').show();
},
addEventBack : function(){   //绑定返回监听
    inv.pushHistory();
    window.addEventListener("popstate",inv.addBackKey, false);
},
removeEventBack : function(){   //解除返回监听
    window.removeEventListener("popstate",inv.addBackKey, false); 
},
pushHistory : function() {   //创造历史记录
    var state = { 
          title: "title", 
          url: "#"
        }; 
        window.history.pushState(state, "title", "#j"); 
}

 

posted @ 2019-10-16 14:47  苹果π  阅读(218)  评论(0)    收藏  举报