android 判断是否平板判断用户是平板还是手机的方法

博客分类:
通过 Agent 来判断相应的智能手机设备,然后跳转到新的手机站点
经过不懈的努力,终于搜集了比较全的 智能设备 的 Agent,然后又写了程序,直接上代码吧,希望能帮助到你
/// 根据 Agent 判断是否是智能手机
///&/summary&
///&returns&&/returns&
public static bool CheckAgent()
bool flag =
string agent = HttpContext.Current.Request.UserA
string[] keywords = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
//排除 Windows 桌面系统
if (!agent.Contains("Windows NT") || (agent.Contains("Windows NT") && agent.Contains(" MSIE 9.0;")))
//排除 苹果桌面系统
if (!agent.Contains("Windows NT") && !agent.Contains("Macintosh"))
foreach (string item in keywords)
if (agent.Contains(item))
代码解释:
1. !agent.Contains("Windows NT") && !agent.Contains("Macintosh") 排除Window 桌面系统 和 苹果桌面系统
2. "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" 这些是判断智能设备Agent中的关键词
3. MQQBrowser 为 QQ 手机浏览器,QQ 手机的Agent 比较特殊,所以单独判断
下面搜集的一些Agent,话说找到这么多的智能设备,好不容易啊:
Mozilla/5.0 (iP U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/
Mozilla/5.0 (iP U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/
MQQBrowser/25 (L U; 2.3.3; zh- HTC Desire S Build/GRI40;480*800)
Mozilla/5.0 (L U; Android 2.3.3; zh- HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1 /110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413
Mozilla/5.0 (iP U; CPU OS 4_3_3 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8J2
Mozilla/5.0 (Windows NT 5.2) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30
Mozilla/5.0 (M Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
Mozilla/5.0 (M Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22
Mozilla/5.0 (iP CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/
Mozilla/5.0 (iP CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/
Mozilla/5.0 (iP CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
Mozilla/5.0 ( MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7)      ----SAMSUNG MP7
Mozilla/5.0 ( MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7)
        ----HTC MP7
* 验证是否为智能手机
$.checkMobile = function(){
var flag =
var agent = navigator.userAgent.toLowerCase();
var keywords = [ "android", "iphone", "ipod", "ipad", "windows phone", "mqqbrowser" ];
//排除 Windows 桌面系统
if (!(agent.indexOf("windows nt") & -1) || (agent.indexOf("windows nt") & -1 && agent.indexOf(" msie 9.0;") & -1)) {
//排除苹果桌面系统
if (!(agent.indexOf("windows nt") & -1) && !agent.indexOf("macintosh") & -1 ) {
for (var item in keywords) {
if (agent.indexOf(item) & -1 ) {
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/ Firefox/12.0
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0. Safari/53
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7
----safari
Mozilla/5.0 ( MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MDDS; InfoPath.2; Alexa Toolbar)
Opera/9.80 (Windows NT 6.1; WOW64; U; zh-cn) Presto/2.10.229 Version/11.64
浏览 78184
浏览: 794027 次
来自: 北京
太好了,谢谢啊。
学习了,谢谢您~
算法有问题,会产生不可见字符,造成信息丢失
该图片仅限百度用户内部交流
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'js判断手机端(Android手机还是iPhone手机)
转载 & & 投稿:mdxy-dxy
现在使用手机上网的人越来越多,一些下载网站会通过判断不同系统手机来访问不同网页,比如iPhone和Android。下面我们就来介绍一下如何用javascript判断iPhone或Android手机访问
网上常用的代码
* [isMobile 判断平台]
* @param test: 0:iPhone 1:Android
function ismobile(test){
var u = navigator.userAgent, app = navigator.appV
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")&0){
if(/iPhone|mac|iPod|iPad/i.test(navigator.userAgent)){
return '0';
return '1';
}catch(e){}
}else if( u.indexOf('iPad') & -1){
return '0';
return '1';
使用方法:
var pla=ismobile(1);
如果pla返回的是0:iPhone 1:Android
&script type="text/javascript"&
var browser = {
versions: function () {
var u = navigator.userAgent, app = navigator.appV
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/i) || !!u.match(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/), //是否为移动终端
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应该程序,没有头部与底部
language: (navigator.browserLanguage || navigator.language).toLowerCase()
if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) {
window.location.href = "http://www.jb51.net";
if (browser.versions.android) {
window.location.href = "http://www.qq.com";
如何判断是否是 iPad 浏览器呢,关键是看它的 User Agent 中是否有 iPad。iPad 使用的是 Safari Mobile 浏览器,他的的 User Agent 是:
Mozilla/5.0 (iP U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
Javascript代码
function is_iPad(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/iPad/i)=="ipad") {
因此,判断ipad,iphone,android的代码为:
&script type="text/javascript"&
var bForcepc = fGetQuery("dv") == "pc";
function fBrowserRedirect(){
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if(bIsIpad){
var sUrl = location.
if(!bForcepc){
window.location.href = "http://m.jb51.net/?ipad";
if(bIsIphoneOs || bIsAndroid){
var sUrl = location.
if(!bForcepc){
window.location.href = "http://m.jb51.net/?iphone";
if(bIsMidp||bIsUc7||bIsUc||bIsCE||bIsWM){
var sUrl = location.
if(!bForcepc){
window.location.href = "http://m.jb51.net/";
function fGetQuery(name){//获取参数值
var sUrl = window.location.search.substr(1);
var r = sUrl.match(new RegExp("(^|&)" + name + "=([^&]*)(&|$)"));
return (r == null ? null : unescape(r[2]));
function fShowVerBlock(){
if(bForcepc){
document.getElementById("dv_block").style.display = "block";
document.getElementById("ad_block").style.display = "block";
fBrowserRedirect();
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具#if UNITY_ANDROID
float physicscreen = Mathf.Sqrt(Screen.width * Screen.width + Screen.height * Screen.height) / Screen.
if (physicscreen &= 7f)
Debug.Log("安卓平板");
Debug.Log("安卓手机");
#elif UNITY_IPHONE
Debug.Log(iPhone.generation);
string iP_genneration = UnityEngine.iOS.Device.generation.ToString();
//The second Mothod:
//string iP_genneration=SystemInfo.deviceModel.ToString();
if (iP_genneration.Substring(<span style="color: #, <span style="color: #) == "iPa")
Debug.Log("苹果平板");
Debug.Log("苹果手机");
阅读(...) 评论()Android中 判断是平板还是手机
//是平板返回true 不是平板返回false
public &boolean isTablet(Context context) {
& return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) &= Configuration.SCREENLAYOUT_SIZE_LARGE;Android判断用户是平板还是手机的方法_百度知道
Android判断用户是平板还是手机的方法
我有更好的答案
Configuration.SCREENLAYOUT_SIZE_MASK) &=Configuration.SCREENLAYOUT_SIZE_LARGE.screenLayout &amp:&return (context:平板,false:手机*/private boolean isTabletDevice(Context context) { & &nbsp/*** 判断是否平板设备* @param context* @return true://blog.}很奇怪,你这个问题不能插入代码编译。链接;<a title="判断是否平板 链接" class="iknow-ueditor-link" href="https.getResources().getConfiguration()
采纳率:72%
为您推荐:
您可能关注的内容
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 js判断设备是否为平板 的文章

 

随机推荐