0

I am trying to use a device and OS detection script and came across with this mobile detect js plugin. It seems pretty clean yet quite confusing.

GITHUB LINK and DOC LINK

It seems the documentation is not thorough and I am finding a bit confusing on how to create special cases. For example, what I am trying to do is to find whether user is visiting website using mobile or tablet and after that check is done the next step is to find the OS of the device.

function deviceDetectionScript() { var md = new MobileDetect(window.navigator.userAgent); if (md.mobile() && md.phone() && md.tablet()) { If(ios) { //do something } If(android) { //do something } If(windows) { //do something } } else { // do something else } } 

However, I am not sure the correct way to achieve this. Or is there any other way around to achieve the similar functionality without using this script?

1
  • You have to be more specific. Saying "something like this" and posting poorly written code won't cut it. What exactly do you want to do? Commented Jul 25, 2014 at 8:46

1 Answer 1

3

For example, what I am trying to do is to find whether user is visiting website using mobile or tables and after that check is done the next step is to find the OS of the device.

Just FYI, tablet is considered mobile.

You have a couple options when it comes to doing what you want.

To check if user is on mobile use md.mobile().

To determine if it is a tablet or phone use md.phone() and md.tablet(). This returns null or brand name.

Finally to check OS use md.os()(it will print name of OS) or you can use md.is('iPhone') which returns true or false.

Other available functions:

md.mobile() // 'Sony' md.phone() // 'Sony' md.tablet() // null md.userAgent() // 'Safari' md.os() // 'AndroidOS' md.is('iPhone') // false md.is('bot') // false md.version('Webkit') // 534.3 md.versionStr('Build') // '4.1.A.0.562' md.match('playstation|xbox') // false 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.