使用Modernizr检测移动设备的最可靠方法是什么? [英] What is the most reliable way to detect a mobile device using Modernizr?
问题描述
我正在开发一个响应性网站,并且当用户在移动设备上浏览时,我被要求将我们网站上的所有免费电话号码交换为固定电话号码.使用Modernizr库(或任何其他库)检测用户是否在移动设备上的最可靠方法是什么?
I am developing a responsive site and I have been asked to swap any freephone numbers on our site to the landline equivalent when a user is browsing on a mobile device. What is the most reliable way to detect if a user is on a mobile device using the Modernizr library (or any other library)?
我知道Modernizr.touch和Modernizr.geolocation.当将两者合并在if(Modernizr.touch && Modernizr.geolocation)
语句中时,它们可以很好地指示您是否在移动设备上,但是iPad将使这两个属性均成立.我不愿意测试设备的尺寸,因为移动设备越来越大!
I am aware of Modernizr.touch and also Modernizr.geolocation. When the two are combined in an if(Modernizr.touch && Modernizr.geolocation)
statement they are a good indicator of whether you are on a mobile device however an iPad will make both these attributes true. I am reluctant to test the device size because mobile devices are getting bigger and bigger!
以前有人解决过吗?
推荐答案
通过使用Modernizr API方法 Modernizr.mq(str)
By using Modernizr API Method Modernizr.mq(str)
示例:
Modernizr.mq('only all and (max-width: 400px)')
这篇关于使用Modernizr检测移动设备的最可靠方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!