欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

H5页面调用原生方法返回

程序员文章站 2024-02-29 19:06:46
...
var userAgent = navigator.userAgent.toLowerCase();
// 调用原生方法返回
function back() {
        if (equipment('iphone')) {
            naviBack({ isRefresh: '0', callBack: 'isRefresh()' });
        } else if (equipment('ipad')) {
            naviBack({ isRefresh: '0', callBack: 'isRefresh()' });
        } else if(equipment('android')) {
            JsBridge.call('JSBridge', 'naviBack', { isRefresh: false, callBack: 'isRefresh()' }, (res) => {});
        } else {
            window.history.go(-1);
        }
}

function equipment(val){
    var res = false;
    var userAgent = navigator.userAgent.toLowerCase();
    console.log(userAgent);
    if(userAgent.indexOf(val) > -1) {
      res = true;
    }
    return res;
  
  };