detectmobilebrowsers –如何添加ipad& co//检测移动浏览器js [英] detectmobilebrowsers – how to add ipad & co // detect mobile browsers js

查看:162
本文介绍了detectmobilebrowsers –如何添加ipad& co//检测移动浏览器js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用检测移动浏览器( http://detectmobilebrowsers.com/)检测iPhone和其他智能手机.现在,我还想添加平板电脑,例如iPad.在网站上,您可以找到以下提示:

i use detect mobile browsers (http://detectmobilebrowsers.com/) to detect iPhones and other smartphones. now i want to add also tablets like iPad. On the website you can find the following hint for this:

未检测到Android平板电脑,iPad,Kindle Fires和PlayBooks 设计.要添加对平板电脑的支持,请向其中添加| android | ipad | playbook | silk 第一个正则表达式.

Android tablets, iPads, Kindle Fires and PlayBooks are not detected by design. To add support for tablets, add |android|ipad|playbook|silk to the first regex.

实际上我的代码是这样的:

Actually my code is like this:

if($.browser.mobile) 
{ 
   // it is mobile browser
}
else
{
   // no mobile browser 
}

如何添加其他属性? ("| android | ipad | playbook | silk")?

How do i have to add the other attributes? ("|android|ipad|playbook|silk")?

推荐答案

修改您正在使用的detectmobilebrowsers代码;

Modify the detectmobilebrowsers code you're using;

在哪里看到正则表达式(我假设您使用的是Javascript版本)

Where you see the regex (I assume you're using the Javascript version)

(function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |ma....

更改为

(function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|android|ipad|playbook|silk|iris|kindle|lge |ma...

或更妙的是,更改为

(function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|android|playbook|silk|iris|kindle|lge |ma...

这篇关于detectmobilebrowsers –如何添加ipad& co//检测移动浏览器js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆