2017年12月21日
微信公众号监听返回按钮问题解决
//首页返回路径
$(function(){
pushHistory();
var bool = false;
setTimeout(function(){
bool = true;
},500);
window.addEventListener("popstate", function(e) {
if(bool){
//手机终端判断
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if(isAndroid){
//WeixinJSBridge.call('closeWindow');
location.href='/';
}else{
location.href='/';
}
}
}, false);
});
function pushHistory() {
var state = {
title: "",
url: "/"
};
window.history.pushState(state, state.title, state.url);
}