goBack: function() { // 回退到APP
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) {
window.WebContrl.finish();
}else {
window.webkit.messageHandlers.finish.postMessage('调用了IOS方法');
}
},toApp:function(){ //h5页面,监听手机物理返回键
var _this = this
history.pushState(null,null,location.href);
window.addEventListener('popstate',function(event){
history.pushState(null,null,location.href);
_this.goBack(); //H5自己定义的方法
});
}
判断安卓终端与ios终端的方法,这里以h5页面回退到app为例 手机物理返回键方法
最新推荐文章于 2022-07-28 15:30:23 发布