在主页判断跳转地址 //判断浏览客户端 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项目
thinkjs判断访问是否是手机客户端方法
最新推荐文章于 2024-07-23 16:33:08 发布