1. 判斷微信
function is_weixin() { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }
2. 判斷Andorid還是ios
$(function () { var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端 if (isAndroid) { //這個是安卓作業系統 } if (isIOS) { //這個是ios作業系統 } });
3. 判斷PC
//如果返回的是false說明當前作業系統是手機端,如果返回的是true則說明當前的作業系統是電腦端 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; }
出處:https://www.cnblogs.com/zhuchenglin/p/7528250.html