Class: MobileDetect

MobileDetect

new MobileDetect(userAgent, maxPhoneWidth)

Constructor for MobileDetect object.
Such an object will keep a reference to the given user-agent string and cache most of the detect queries.
Find information how to download and install: github.com/hgoebl/mobile-detect.js/
Parameters:
Name Type Argument Default Description
userAgent string typically taken from window.navigator.userAgent or http_header['User-Agent']
maxPhoneWidth number <optional>
650 only for browsers specify a value for the maximum width (in logical "CSS" pixels) until a device detected as mobile will be handled as phone. This is only used in cases where the device cannot be classified as phone or tablet.
See A non-responsive approach to building cross-device webapps.
If you provide a value < 0, then this "fuzzy" check is disabled.
Source:
Example
 
    var md = new MobileDetect(window.navigator.userAgent);
    if (md.mobile()) {
        location.href = (md.mobileGrade() === 'A') ? '/mobile/' : '/lynx/';
    }

Methods

is(key) → {boolean}

Global test key against userAgent, os, phone, tablet and some other properties of userAgent string.
Parameters:
Name Type Description
key String the key (case-insensitive) of a userAgent, an operating system, phone or tablet family.
For a complete list of possible values, see MobileDetect#userAgent, MobileDetect#os, MobileDetect#phone, MobileDetect#tablet.
Additionally you have following keys:

DesktopMode, TV, WebKit, Bot, MobileBot, Console, Watch
Source:
Returns:
true when the given key is one of the defined keys of userAgent, os, phone, tablet or one of the listed additional keys, otherwise false
Type
boolean

match(pattern) → {boolean}

Do a quick test against navigator::userAgent.
Parameters:
Name Type Description
pattern String | RegExp the pattern, either as String or RegExp (a string will be converted to a case-insensitive RegExp).
Source:
Returns:
true when the pattern matches, otherwise false
Type
boolean

mobile() → {String}

Returns the detected phone or tablet type or null if it is not a mobile device.
For a list of possible return values see MobileDetect#phone and MobileDetect#tablet.

If the device is not detected by the regular expressions from Mobile-Detect, a test is made against the patterns of detectmobilebrowsers.com. If this test is positive, a value of UnknownPhone, UnknownTablet or UnknownMobile is returned.
When used in browser, the decision whether phone or tablet is made based on screen.width.
When used server-side (node.js), there is no way to tell the difference between UnknownPhone and UnknownTablet, so you will only get UnknownMobile.

In most cases you will use the return value just as a boolean.
Source:
Returns:
the key for the phone family or tablet family, e.g. "Nexus".
Type
String

mobileGrade() → {String}

Returns the mobile grade ('A', 'B', 'C').
Source:
Returns:
one of the mobile grades ('A', 'B', 'C').
Type
String

os() → {String}

Returns the detected operating system string or null.
The operating system is one of following keys:

AndroidOS, BlackBerryOS, PalmOS, SymbianOS, WindowsMobileOS, WindowsPhoneOS, iOS, MeeGoOS, MaemoOS, JavaOS, webOS, badaOS, BREWOS
Source:
Returns:
the key for the detected operating system.
Type
String

phone() → {String}

Returns the detected phone type/family string or null.
The returned tablet (family or producer) is one of following keys:

iPhone, BlackBerry, HTC, Nexus, Dell, Motorola, Samsung, LG, Sony, Asus, Micromax, Palm, Vertu, Pantech, Fly, iMobile, SimValley, Wolfgang, Alcatel, Nintendo, Amoi, INQ, GenericPhone

If the device is not detected by the regular expressions from Mobile-Detect, a test is made against the patterns of detectmobilebrowsers.com. If this test is positive, a value of UnknownPhone or UnknownMobile is returned.
When used in browser, the decision whether phone or tablet is made based on screen.width.
When used server-side (node.js), there is no way to tell the difference between UnknownPhone and UnknownMobile, so you will only get UnknownMobile.

In most cases you will use the return value just as a boolean.
Source:
Returns:
the key of the phone family or producer, e.g. "iPhone"
Type
String

tablet() → {String}

Returns the detected tablet type/family string or null.
The returned tablet (family or producer) is one of following keys:

iPad, NexusTablet, 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, 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, OdysTablet, CaptivaTablet, IconbitTablet, TeclastTablet, JaytechTablet, BlaupunktTablet, DigmaTablet, EvolioTablet, NexoTablet, UbislateTablet, PocketBookTablet, Hudl, TelstraTablet, GenericTablet

If the device is not detected by the regular expressions from Mobile-Detect, a test is made against the patterns of detectmobilebrowsers.com. If this test is positive, a value of UnknownTablet or UnknownMobile is returned.
When used in browser, the decision whether phone or tablet is made based on screen.width.
When used server-side (node.js), there is no way to tell the difference between UnknownTablet and UnknownMobile, so you will only get UnknownMobile.

In most cases you will use the return value just as a boolean.
Source:
Returns:
the key of the tablet family or producer, e.g. "SamsungTablet"
Type
String

userAgent() → {String}

Returns the detected user-agent string or null.
The returned user-agent is one of following keys:

Chrome, Dolfin, Opera, Skyfire, IE, Firefox, Bolt, TeaShark, Blazer, Safari, Tizen, UCBrowser, baiduboxapp, baidubrowser, DiigoBrowser, Puffin, Mercury, ObigoBrowser, NetFront, GenericBrowser
Source:
Returns:
the key for the detected user-agent or null
Type
String

version(key) → {Number}

Get the version (as Number) of the given property in the User-Agent.
Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
Parameters:
Name Type Description
key String a key defining a thing which has a version.
You can use one of following keys:

Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast, Dolfin, Firefox, Fennec, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera Mobi, UC Browser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, Safari, Skyfire, Tizen, Webkit, Gecko, Trident, Presto, iOS, Android, BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows NT, Symbian, webOS
Source:
Returns:
the version as float or NaN if User-Agent doesn't contain this version. Be careful when comparing this value with '==' operator!
Type
Number

versionStr(key) → {String}

Get the version (as String) of the given property in the User-Agent.
Parameters:
Name Type Description
key String a key defining a thing which has a version.
You can use one of following keys:

Mobile, Build, Version, VendorID, iPad, iPhone, iPod, Kindle, Chrome, Coast, Dolfin, Firefox, Fennec, IE, NetFront, NokiaBrowser, Opera, Opera Mini, Opera Mobi, UC Browser, MQQBrowser, MicroMessenger, baiduboxapp, baidubrowser, Safari, Skyfire, Tizen, Webkit, Gecko, Trident, Presto, iOS, Android, BlackBerry, BREW, Java, Windows Phone OS, Windows Phone, Windows CE, Windows NT, Symbian, webOS
Source:
Returns:
the "raw" version as String or null if User-Agent doesn't contain this version.
Type
String