在WeChat,Alipay,百度钱包可以单击后退按钮关闭当前页面和窗口的方法

最近在WeChat,Alipay,百度钱包使用网上支付,支付成功会自动关闭网页,不付,将显示错误信息。当页面的错误页面,页面关闭时点击返回或Android物理按钮一步。

在WeChat,Alipay,百度钱包,他们的页面关闭的包装,传统的window.close()是无效的,需要使用JS代码关闭。

以下是三种移动应用程序的关闭:


weixinjsbridge.call('closewindow '); / /微信
AlipayJSBridge.call('closewebview '); / /支付宝
(BLightApp。关闭一个窗口); / /百度钱包


浏览器的头部判断是浏览器的一种:


var ua = navigator.useragent.tolowercase();
F(ua.match( / /我micromessenger)= micromessenger){
警报(微信客户端);
} else if(ua.indexof(支付宝)!= 1){
警报(支付宝客户端);
} else if(ua.indexof(百度)!= 1){
警报(百度客户机);
}


请听返回、返回和返回,并将当前页地址放入历史记录中:


$(函数(){())
PushHistory();
Window.addEventListener(popstate
},假);
功能pushhistory(){
var状态= {
标题:标题
网址:#
};
window.history.pushstate(状态,标题
}
});


代码的全部实现:


$(函数(){())
PushHistory();
Window.addEventListener(popstate
PushHistory();
var ua = navigator.useragent.tolowercase();
如果(ua.match( / /我micromessenger)= micromessenger){
weixinjsbridge.call('closewindow);
} else if(ua.indexof(支付宝)!= 1){
AlipayJSBridge.call('closewebview);
} else if(ua.indexof(百度)!= 1){
BLightApp.closeWindow();
}
别的{
Window.close();
}
},假);
功能pushhistory(){
var状态= {
标题:标题
网址:#
};
window.history.pushstate(状态,标题
}
});


The above is Xiaobian to introduce in WeChat, Alipay, Baidu wallet can click the back button and the current page method to close the window, I hope to help you, if you have any questions please give me a message, Xiao Bian will reply you timely.Thank you for your support for the website.