微信浏览器关闭

1,534 阅读1分钟

一、解决window.close失效问题

function f_close(){
  if(typeof(WeixinJSBridge)!="undefined"){
    WeixinJSBridge.call('closeWindow');
  }else{
    if (navigator.userAgent.indexOf("MSIE") > 0) {  
      if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {  
        window.opener = null; window.close();  
      } else {  
        window.open('', '_top'); window.top.close();  
      }  
    } else if (navigator.userAgent.indexOf("Firefox") > 0) {  
      window.location.href = 'about:blank ';  
      //window.history.go(-2);  
    } else {  
      window.opener = null;   
      window.open('', '_self', '');  
      window.close();  
    }
  }

二、针对个人问题,IOS手机和安卓手机都能关闭(两个的前后顺序不能调换)


setTimeout(function(){
  //这个可以关闭安卓系统的手机
  document.addEventListener('WeixinJSBridgeReady', function(){ WeixinJSBridge.call('closeWindow'); }, false);
  //这个可以关闭ios系统的手机
  WeixinJSBridge.call('closeWindow');
}, 1000)