支付宝支付功能关闭怎么开启


支付宝支付功能关闭怎么开启

文章插图
最近在使用微信、支付宝、百度钱包实现网页支付,对支付成功将自动关闭页面,对于支付失败,将显示错误信息 。当在错误页面的时候,点击返回
或者Android物理按键上一步的时候,将关闭页面 。
在微信、支付宝、百度钱包中,他们对页面关闭进行了封装,传统的window.close()是无效的,必须要使用它们的js代码才能关闭 。下面是三种移动app
的关闭方式:
WeixinJSBridge.call('closeWindow');//微信AlipayJSBridge.call('closeWebview'); //支付宝BLightApp.closeWindow();//百度钱包通过浏览器的头判断是那种浏览器:
var ua = navigator.userAgent.toLowerCase(); f(ua.match(/MicroMessenger/i)=="micromessenger") {alert("微信客户端"); } else if(ua.indexOf("alipay")!=-1){alert("支付宝客户端"); }else if(ua.indexOf("baidu")!=-1){alert("百度客户端"); }对返回、上一页、后退进行监听,并对history中放入当前页地址:
【支付宝支付功能关闭怎么开启】$(function(){pushHistory();window.addEventListener("popstate", function(e) {}, false);function pushHistory() {var state = {title: "title",url: "#"};window.history.pushState(state, "title", "#");} });整个实现完整代码:
$(function(){pushHistory();window.addEventListener("popstate", function(e) {pushHistory();var ua = navigator.userAgent.toLowerCase();if(ua.match(/MicroMessenger/i)=="micromessenger") {WeixinJSBridge.call('closeWindow');} else if(ua.indexOf("alipay")!=-1){AlipayJSBridge.call('closeWebview');}else if(ua.indexOf("baidu")!=-1){BLightApp.closeWindow();}else{window.close();}}, false);function pushHistory() {var state = {title: "title",url: "#"};window.history.pushState(state, "title", "#");}});