Another loose port of https://github.com/serbanghita/Mobile-Detect for Javascript, to get latest detections. As https://github.com/hgoebl/mobile-detect.js doesn't update anymore.
Both great projects!
- HTTP headers' code is removed
- caching code is removed
- exceptions are removed
- regular expressions are simplified in the
build.phpso that there's no sub-arrays to parse
Just copy the mobile-detect.js or the minimized version mobile-detect.min.js into your project. You can use the raw link for direct download (link is available by clicking on the file above, then there's a Raw button).
// fallsback to navigator.userAgent
var md = new MobileDetect();
// or set it explicitly
var md = new MobileDetect('Mozilla/5.0');Then you can use the (currently) implemented methods:
md.isMobile(); // or md.is('mobile')
md.isPhone(); // or md.is('phone')
md.isTablet(); // or md.is('tablet')For dedicated checks, you have the full set of names here: methods in PHP project
But do NOT use the md.isiPhone() statement, it's not implemented. You MUST always use the md.is('iPhone') method instead.
md.is('iPhone'); // or md.is('iphone'), it's case-insensitive
md.is('AndroidOS');