該插件用來(lái)獲取移動(dòng)端設(shè)備信息。
1.下載與安裝
方法一: 使用cdn在html頁(yè)面引入
mobile-detect的cdn(這兩個(gè)地址都可以):
(1)https://cdn.jsdelivr.net/npm/mobile-detect@1.4.3/mobile-detect.min.js
(2)https://cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.4.3/mobile-detect.min.js
方法二: 使用npm/bower工具下載
(1)npm的mobile-detect地址:https://www.npmjs.com/package/mobile-detect
$ npm install mobile-detect --save
下載完后在需要用的頁(yè)面或者全局import引入進(jìn)去侧甫。
(2)bower下載
$ bower install hgoebl/mobile-detect.js --save
2.使用
(1) 由cdn引入的使用方法
(2) 由工具下載的使用方法
3.mobile-detect的屬性方法
(1) mobile()
獲取手機(jī)或平板電腦類型,若不是移動(dòng)設(shè)備染服,則返回null漓帚。若檢測(cè)不到設(shè)備蹬敲,則會(huì)返回UnknownPhone或UnknownTablet或UnknownMobile壳坪。
可能得到的值:phone()的值和tablet()的值
(2) mobileGrade()
返回移動(dòng)設(shè)備等級(jí)舶得。
可能得到的值:'A','B','C'
(3) phone()
可能得到的值:iPhone, BlackBerry, HTC, Nexus, Dell, Motorola, Samsung, LG, Sony, Asus, NokiaLumia, Micromax, Palm, Vertu, Pantech, Fly, Wiko, iMobile, SimValley, Wolfgang, Alcatel, Nintendo, Amoi, INQ, GenericPhone
(4) tablet()
返回平板電腦系列或制作人的關(guān)鍵,例如“SamsungTablet”爽蝴。無(wú)則返回null沐批。
可能得到的值:iPad, NexusTablet, GoogleTablet, SamsungTablet, Kindle, SurfaceTablet, HPTablet, AsusTablet, BlackBerryTablet, HTCtablet, MotorolaTablet, NookTablet, AcerTablet, ToshibaTablet, LGTablet, FujitsuTablet, PrestigioTablet, LenovoTablet, DellTablet, YarvikTablet, MedionTablet, ArnovaTablet, IntensoTablet, IRUTablet, MegafonTablet, EbodaTablet, AllViewTablet, ArchosTablet, AinolTablet, NokiaLumiaTablet, SonyTablet, PhilipsTablet, CubeTablet, CobyTablet, MIDTablet, MSITablet, SMiTTablet, RockChipTablet, FlyTablet, bqTablet, HuaweiTablet, NecTablet, PantechTablet, BronchoTablet, VersusTablet, ZyncTablet, PositivoTablet, NabiTablet, KoboTablet, DanewTablet, TexetTablet, PlaystationTablet, TrekstorTablet, PyleAudioTablet, AdvanTablet, DanyTechTablet, GalapadTablet, MicromaxTablet, KarbonnTablet, AllFineTablet, PROSCANTablet, YONESTablet, ChangJiaTablet, GUTablet, PointOfViewTablet, OvermaxTablet, HCLTablet, DPSTablet, VistureTablet, CrestaTablet, MediatekTablet, ConcordeTablet, GoCleverTablet, ModecomTablet, VoninoTablet, ECSTablet, StorexTablet, VodafoneTablet, EssentielBTablet, RossMoorTablet, iMobileTablet, TolinoTablet, AudioSonicTablet, AMPETablet, SkkTablet, TecnoTablet, JXDTablet, iJoyTablet, FX2Tablet, XoroTablet, ViewsonicTablet, VerizonTablet, OdysTablet, CaptivaTablet, IconbitTablet, TeclastTablet, OndaTablet, JaytechTablet, BlaupunktTablet, DigmaTablet, EvolioTablet, LavaTablet, AocTablet, MpmanTablet, CelkonTablet, WolderTablet, MediacomTablet, MiTablet, NibiruTablet, NexoTablet, LeaderTablet, UbislateTablet, PocketBookTablet, KocasoTablet, HisenseTablet, Hudl, TelstraTablet, GenericTablet
(5) userAgent()
返回(第一個(gè))檢測(cè)到的用戶代理。無(wú)則返回null蝎亚。
可能得到的值:Chrome, Dolfin, Opera, Skyfire, Edge, IE, Firefox, Bolt, TeaShark, Blazer, Safari, WeChat, UCBrowser, baiduboxapp, baidubrowser, DiigoBrowser, Puffin, Mercury, ObigoBrowser, NetFront, GenericBrowser, PaleMoon
(6) userAgents()
返回檢測(cè)到的所有用戶代理九孩。無(wú)則返回null。
(7) os()
檢測(cè)操作系統(tǒng)发框,返回操作系統(tǒng)字符串或者null躺彬。
可能得到的值:AndroidOS, BlackBerryOS, PalmOS, SymbianOS, WindowsMobileOS, WindowsPhoneOS, iOS, MeeGoOS, MaemoOS, JavaOS, webOS, badaOS, BREWOS
(8) is(key)
從userAgent, os, phone, tablet和其他有關(guān)userAgent的屬性中判斷是否有key這個(gè)字符串。
舉個(gè)栗子:
(9) version(key)
獲取User-Agent中給定屬性的版本(將返回一個(gè)浮點(diǎn)數(shù))梅惯。無(wú)則返回null顾患。
key的值可以是:Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast, Dolfin, Firefox, Fennec, Edge, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera Mobi, UCBrowser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, SamsungBrowser, Iron, Safari, Skyfire, Tizen, Webkit, PaleMoon, Gecko, Trident, Presto, Goanna, iOS, Android, BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows NT, Symbian, webOS
(10) versionStr(key)
獲取User-Agent中給定屬性的版本(作為String)。無(wú)則返回null个唧。
key的值可以是:Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast, Dolfin, Firefox, Fennec, Edge, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera Mobi, UCBrowser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, SamsungBrowser, Iron, Safari, Skyfire, Tizen, Webkit, PaleMoon, Gecko, Trident, Presto, Goanna, iOS, Android, BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows NT, Symbian, webOS
(11) match(pattern)
pattern的類型為正則或者字符串。
舉個(gè)子: