繁体   English   中英

如何确定设备是否为桌面浏览器?

[英]How do I determine if a device is a desktop browser?

我正在为网站创建响应式设计。 我们为非触摸式桌面浏览器提供了一个过渡导航菜单,为触摸移动和触摸平板提供了非画布菜单设计。 这是一个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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM