isMobile 一个简单的JS库,用来检测移动设备
2015-04-06 11:17
405 查看
点这里
github地址:https://github.com/kaimallea/isMobile
Usage
github地址:https://github.com/kaimallea/isMobile
Example Usage
I include the minified version of the script, inline, and at the top of the<head>. Cellular connections tend to suck, so it would be wasteful overhead to open another connection, just to download <1kb of JS:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <script> // Minified version of isMobile included in the HTML since it's <1kb (function(i){var e=/iPhone/i,n=/iPod/i,o=/iPad/i,t=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,r=/Android/i,d=/BlackBerry/i,s=/Opera Mini/i,a=/IEMobile/i,b=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,h=RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),c=function(i,e){return i.test(e)},l=function(i){var l=i||navigator.userAgent;this.apple={phone:c(e,l),ipod:c(n,l),tablet:c(o,l),device:c(e,l)||c(n,l)||c(o,l)},this.android={phone:c(t,l),tablet:!c(t,l)&&c(r,l),device:c(t,l)||c(r,l)},this.other={blackberry:c(d,l),opera:c(s,l),windows:c(a,l),firefox:c(b,l),device:c(d,l)||c(s,l)||c(a,l)||c(b,l)},this.seven_inch=c(h,l),this.any=this.apple.device||this.android.device||this.other.device||this.seven_inch},v=i.isMobile=new l;v.Class=l})(window); // My own arbitrary use of isMobile, as an example (function () { var MOBILE_SITE = '/mobile/index.html', // site to redirect to NO_REDIRECT = 'noredirect'; // cookie to prevent redirect // I only want to redirect iPhones, Android phones and a handful of 7" devices if (isMobile.apple.phone || isMobile.android.phone || isMobile.seven_inch) { // Only redirect if the user didn't previously choose // to explicitly view the full site. This is validated // by checking if a "noredirect" cookie exists if ( document.cookie.indexOf(NO_REDIRECT) === -1 ) { document.location = MOBILE_SITE; } } })(); </script> </head> <body> <!-- imagine lots of html and content --> </body> </html>
node.js usage
Installationnpm install ismobilejs
Usage
var isMobile = require('ismobilejs'); console.log(isMobile(req.headers['user-agent']).any);
相关文章推荐
- isMobile 一个简单的JS库,用来检测移动设备
- isMobile 一个简单的JS库,用来检测移动设备
- 简单的移动设备检测PHP脚本代码
- 简单的移动设备检测PHP脚本
- 分享一个检测用户使用的移动设备类型的php class
- 简单的移动设备检测PHP脚本代码
- 一个可以用来站内检索的简单爬虫
- 一个用来重整resource.h中id的简单脚本
- 一个很有用的检测USB设备插入拔出的对象
- Monkey 是运行在模拟器或设备上的一个工具,用来伪随机
- 关于移动设备上GIS系统开发的一个问题(EVC+MapXMobile)
- 关于移动设备上GIS系统开发的一个问题(EVC+MapXMobile)
- 一个简单的分页控件,用来自定义分页用的
- Java写的一个简单的图片移动小程序
- Learning OpenCV: 一个简单的人眼检测程序
- 【转帖】驱动开发之一 --- 创建一个简单的设备驱动 【译文】
- 一个简单的演示用的Linux字符设备驱动程序
- 一个简单的分页控件,用来自定义分页用的
- 前些日子做的一个电力设备检测软件
- 检测移动设备 OnDeviceChange(ON_WM_DEVICECHANGE)