下面是三种移动app的关闭方式:
1
2
3
|
WeixinJSBridge.call(
'closeWindow'
);
//微信
AlipayJSBridge.call(
'closeWebview'
);
//支付宝
BLightApp.closeWindow();
//百度钱包
|
通过浏览器的头判断是那种浏览器:
1
2
3
4
5
6
7
8
|
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中放入当前页地址:
1
2
3
4
5
6
7
8
9
10
11
12
|
$(function(){
pushHistory();
window.addEventListener(
"popstate"
, function(e) {
},
false
);
function pushHistory() {
var state = {
title:
"title"
,
url:
"#"
};
window.history.pushState(state,
"title"
,
"#"
);
}
});
|
整个实现完整代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
$(
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"
,
"#"
);
}
});
|