通过navigator的userAgent属性来判定
userAgent 属性是一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值。一般来讲,它是在 navigator.appCodeName 的值之后加上斜线和 navigator.appVersion 的值构成的。
例如:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)
1 function checkBrowser(){
2 var browser={
3 versions:function(){
4 var u = navigator.userAgent, app = navigator.appVersion;
5 return {
6 //移动终端浏览器版本信息
7 trident: u.indexOf('Trident') > -1, //IE内核
8 presto: u.indexOf('Presto') > -1, //opera内核
9 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
10 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
11 mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端
12 ios: !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
13 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
14 iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
15 iPad: u.indexOf('iPad') > -1, //是否iPad
16 webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
17 };
18 }(),
19 language:(navigator.browserLanguage || navigator.language).toLowerCase()
20 }
21 if( browser.versions.android || browser.versions.iPhone || browser.versions.iPad){
22 window.location.href="http://daimami.com“
23
24 }
25 }
通过navigator的platform来判断
platform 属性是一个只读的字符串,声明了运行浏览器的操作系统和(或)硬件平台。虽然该属性没有标准的值集合,但它有些常用值,比如 "Win32"、"MacPPC" 以及 "Linuxi586",等等。
<!--
//平台、设备和操作系统
var system ={
win : false,
mac : false,
xll : false //X11也叫做X Window系统,X Window系统 (X11或X)是一种 位图 显示的 视窗系统 。它是在 Unix 和 类Unix 操作系统 ,以及 OpenVMS 上建立图形用户界面
的标准工具包和协议,并可用于几乎所有已有的现代操作系统。
};
//检测平台
var p = navigator.platform;
alert(p);
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
//跳转语句
if(system.win||system.mac||system.xll){ //转向电脑端
window.location.href="www.daimami.com";
}else{
window.location.href="www.daimami.com"; //转向手机端}