判断微信支付宝浏览器并拦截后退按钮实现关闭窗口

pushHistory(); 
window.addEventListener("popstate", function(e) { 

var ua = navigator.userAgent.toLowerCase(); 
if(ua.match(/MicroMessenger/i)=="micromessenger") { 
WeixinJSBridge.call('closeWindow'); 
} else if(ua.indexOf("alipay")!=-1){ 
AlipayJSBridge.call('closeWebview'); 
}
else{ 
window.close(); 

}, false); 


function pushHistory() { 
var state = { 
title: "title", 
url: "#"
}; 
window.history.pushState(state, "title", "#"); 

你可能感兴趣的:(判断微信支付宝浏览器并拦截后退按钮实现关闭窗口)