thinkjs判断访问是否是手机客户端方法

来源:互联网 发布:智能软件开发 编辑:程序博客网 时间:2024/06/05 20:25
在主页判断跳转地址//判断浏览客户端if(checkMobile(this.userAgent())){   return this.display('手机端页面') }else{   return this.display("电脑端页面");  }在bootstrap下的global建立全局方法/**
 * 验证是否为智能手机 * @ param {string} data :this.userAgent; * @ return {bool} *//** global checkMobile */global.checkMobile = function(agent) {    let flag = false;    agent = agent.toLowerCase();    let keywords = ["android", "iphone", "ipod", "ipad", "windows phone", "mqqbrowser"];    //排除 Windows 桌面系统      if (!(agent.indexOf("windows nt") > -1) || (agent.indexOf("windows nt") > -1 && agent.indexOf("compatible; msie 9.0;") > -1)) {        //排除苹果桌面系统          if (!(agent.indexOf("windows nt") > -1) && !agent.indexOf("macintosh") > -1) {            for (let item of keywords) {                if (agent.indexOf(item) > -1) {                    flag = true;                    break;                }            }        }    }    return flag;}


以上方法摘取cmswing项目
0 0