JavaScript判断是手机登陆还是pc登陆
2013-05-08 16:46
316 查看
JavaScript不管是判断PC浏览器还是手机浏览器,都是通过User Agent 来判断。 <coding-1 lang="other"> <script type="text/javascript"> var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核 mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器 iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器 iPad: u.indexOf('iPad') > -1, //是否iPad webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部 }; }() } document.writeln(" 是否为移动终端: "+browser.versions.mobile); document.writeln(" ios终端: "+browser.versions.ios); document.writeln(" android终端: "+browser.versions.android); document.writeln(" 是否为iPhone: "+browser.versions.iPhone); document.writeln(" 是否iPad: "+browser.versions.iPad); document.writeln(navigator.userAgent); </script> </coding>
相关文章推荐
- JavaWeb:后台判断是手机登陆还是Pc登陆
- php判断是手机登陆还是PC登陆
- PHP和JAVASCRIPT判断访客终端是电脑还是手机
- JS判断客户端是手机还是PC的2个代码
- 判断访问网站的客户端是PC还是手机
- PHP和javascript判断访客终端是电脑还是手机
- js判断PC还是手机自动跳转代码
- PHP判断客户端是PCweb端还是移动手机端方法
- PHP判断客户端是PCweb端还是移动手机端方法
- wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect
- JS判断登陆端是PC还是手机
- 判断终端是手机还是PC
- 服务器端判断是PC访问还是手机访问
- ASP 中如何判断PC用户访问还是手机用户访问
- 代码分享:JS判断登陆端是PC还是手机
- js判断是pc还是手机
- 判断是手机访问还是PC访问
- 判断当前的浏览器是pc还是移动设备,如果是手机,就跳转到对应手机端网站
- JS判断客户端是手机还是PC的2个代码
- 判断访问用户类型(手机用户还是pc用户)