我正在为网站创建响应式设计。我们为非触摸式桌面浏览器提供了滚动导航菜单,为触摸式移动设备和触摸式平板电脑提供了非 Canvas 菜单设计。它是一个 ASP.NET MVC4 元素。如果用户正在使用桌面浏览器浏览网站,我如何确定 C#、Javascript 或 CSS3?如果可能的话,我更愿意使用某种 CSS3 媒体查询。
最佳答案
来自一个美丽的网站: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
}
否则使用像 device.js 这样的库 http://matthewhudson.me/projects/device.js/
关于c# - 如何确定设备是否为桌面浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045306/