当前代码如下:
$(function () {
window.history.pushState({}, "");
window.addEventListener("popstate", function (e) {
setTimeout(function () {
alert(navigator.userAgent.toLowerCase());
if (/android/.test(navigator.userAgent.toLowerCase()) && isWeiXin()){
alert("android wechat");
WeixinJSBridge.invoke('closeWindow');
} else if (/(iphone|ipad|ipod|ios)/.test(navigator.userAgent.toLowerCase()) && isWeiXin()){
alert("ios wechat");
WeixinJSBridge.invoke('closeWindow');
}else{
alert("other");
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
window.location.href="about:blank";
}else if(userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1){
window.opener=null;window.open('about:blank','_self','').close();
}else {
window.opener = null;
window.open("about:blank", "_self");
window.close();
}
}
}, 300);
});
});
/**
* 判断是否是微信内置浏览器
*
* @returns boolean
*/
function isWeiXin() {
var ua = window.navigator.userAgent;
return ua.toLowerCase().indexOf("micromessenger") > 0;
}
在android的微信、移动浏览器里都是在按下返回才出发了这段代码。
为什么在ios的微信浏览器或safari里进这个画面就触发了呢???