Comments (11)
Not sure if this help's but this how I have adapted the functionality to detect Desktop, Phone, Tablet and Mobile (Phone and Tablet)
isMatchingDeviceType(device) {
if (typeof device === 'undefined') {
return true;
}
if (['ALL', 'MOBILE', 'PHONE', 'DESKTOP', 'TABLET'].indexOf(device) == -1 || device === "ALL") {
return true;
}
var md = new MobileDetect(this.userAgent);
var isMobile = md.mobile() !== null, isPhone = md.phone() !== null, isTablet = md.tablet() !== null;
if (device === "DESKTOP" && !isMobile) {
return true;
}
if (device === "MOBILE" && isMobile) {
return true;
}
if (device === "TABLET" && isTablet) {
return true;
}
if (device === "PHONE" && isPhone) {
return true;
}
return false;
}
from mobile-detect.js.
bumping this. I started off using mobile detect for a responsive web app but now I need to have custom functionality on desktop
from mobile-detect.js.
Can you tell me the value for window.navigator.userAgent
please? (You can use the JavaScript console to get the value.) On which browser and operating system have you encountered the problem?
from mobile-detect.js.
With Node.js, here are the tests:
Windows 7
a) Chrome: "Chrome: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
b) Firefox "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"
c) Yandex Browser: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.13014 YaBrowser/13.12.1599.13014 Safari/537.36"
d) IE: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"
Mac
a) Chrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36"
b) Safari: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71"
from mobile-detect.js.
Maybe, I'm doing something wrong
from mobile-detect.js.
Can you double-check whether you call the constructor of MobileDetect "class" with the userAgent as argument?
var md = new MobileDetect(window.navigator.userAgent);
from mobile-detect.js.
@alexmatveev to check for a desktop device you have to first check if it's mobile, hence isDesktop is not available.
from mobile-detect.js.
in route:
var MobileDetect = require('mobile-detect');
res.locals.md = new MobileDetect(req.headers['user-agent']);
in view (jade):
=md.userAgent()
=md.os()
from mobile-detect.js.
@serbanghita But there are more options: TV, DesktopMode, Watch, etc. So I must to check all of them and if they all are FALSE, mean that it's a desktop?
from mobile-detect.js.
@alexmatveev you haven't done anything wrong. The problem you're encountering is, that MobileDetect has a strong focus on mobile devices and leaves desktop a bit in the dark.
This means that md.userAgent()
and md.os()
only return detected mobile userAgents and OSs.
You can see some "extensions" if you have a look at mobile-usage.
Extending mobile-detect.js to classify desktop browsers and operating system would not be a bad idea. But at the moment I don't have a good idea how to keep backward compatibility.
Any suggestion?
from mobile-detect.js.
Extending mobile-detect.js to classify desktop browsers and operating system would not be a bad idea. But at the moment I don't have a good idea how to keep backward compatibility.
Any suggestion?
I would suggest a separate library (device-detect.js
?) which incorporates these desktop enhancements :) Love this library and would very much love to see this enhancement come to fruition!
from mobile-detect.js.
Related Issues (20)
- Difference between MobileDetect.phone() and MobileDetect.mobile() HOT 1
- OnePlus 5 not detected as Phone HOT 1
- How to detect if it's mobile and not browser but native apps HOT 1
- IE11 userAgent() doesn't return 'IE' HOT 3
- Does not detect iOS 13 beta HOT 8
- 请问一下调用这个函数的时候出现this.ua is not defined?有遇到过? HOT 1
- Mobile detect is not defined HOT 1
- Not working on safari browser to detect ios devices HOT 1
- Documentation question regarding "warning" HOT 1
- floating number wrong: md.version("iPhone") HOT 1
- Unable to detect iPad running iOS 13 HOT 6
- Update device list HOT 1
- cannot detect iPad Pro (iPadOS) HOT 2
- does not identify iPadOS on iPad mini HOT 4
- Add Miui detection support HOT 1
- Samsung Fold devices are not being detected in mobile devices. HOT 1
- [NEW] Detect Device Details with Detective API HOT 6
- update Mobile detect to smth from 2.8.41
- Getting Invalid value when using this this.md().tablet() ==> SkkTablet
- The OS of the system cannot be obtained!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobile-detect.js.