vue wechat h5 homepage slide left to exit method

Because WeChat requires authorization to jump to the code page. At this time, the browser actually has two history pages. If you swipe left with a gesture, you will return to the previous page. It may be blank or it may be automatically refreshed to become two identical pages.

online programs are 

function pushHistory() {
  var state = {
      title: "title",
      url: ""
  };
  window.history.pushState(state, "title", "");
}
window.addEventListener("popstate", function(e) {...//下面的代码写在这里面})

However, it does not meet my needs, so I added some judgments to this plan

First judge ios or android 

var ua= window.navigator.userAgent.toLowerCase();
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isAndroid) {
 pushHistory();
 window.addEventListener("popstate", function(e) {
 //根据自己的需求实现自己的功能
 if(localStorage.getItem("address") === 'inventory' || localStorage.getItem("address") === 'enter') {
    // alert(sessionStorage.getItem("address"));
    if( (ua.match(/MicroMessenger/i) == 'micromessenger') && (ua.match(/wxwork/i) == 'wxwork') ){
       // alert("企业微信客户端");
       window.close();
     }else if( ua.match(/micromessenger/i) == 'micromessenger' ){
       // alert("微信客户端");
       WeixinJSBridge.call('closeWindow');
     }
  }
 }, false);
}
if (isIOS) {
 pushHistory();
 window.addEventListener("popstate", function(e) {
    //根据自己的需求实现自己的功能 这里判断的是首页左滑 退出
    if(localStorage.getItem("address") === 'inventory' || localStorage.getItem("address") === 'enter') {
       // alert(sessionStorage.getItem("address"));
       if( (ua.match(/MicroMessenger/i) == 'micromessenger') && (ua.match(/wxwork/i) == 'wxwork') ){
         // alert("企业微信客户端");
         window.history.go(-1);
        }else if( ua.match(/micromessenger/i) == 'micromessenger' ){
          // alert("微信客户端");
          window.close();
        }
     }
 }, false);
}

Enterprise WeChat uses window.history.go(-1); because it will return twice when exiting instead of staying in the chat box and returning to the workbench

Guess you like

Origin blog.csdn.net/u013194063/article/details/116521715