I am creating a responsive design for a website. We have a rollover navigation menu for non-touch desktop browsers and an off canvas menu design for touch mobile and touch tablets. It is an ASP.NET MVC4 project. How can I determine in C#, Javascript, or CSS3 if a user is browsing the site with a desktop browser? I would prefer to use some kind of CSS3 media query if it is possible.
From a beautiful site: http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if(isMobile.any()){
// Mobile!
} else {
// It is desktop
}
Else use libraries like device.js http://matthewhudson.me/projects/device.js/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.