我有一个工作正常的HTML5指南针。现在,我需要一种聪明的方法来区分“伪面向设备支持”浏览器(如桌面铬和FF)和真正的候选浏览器,比如iPhone/Android/iPad浏览器,它们使用设备的磁力仪。
我目前的解决方案是对DeviceOrientationEvent和触摸支持的基本检查:
if (window.DeviceOrientationEvent && 'ontouchstart' in window) {
// setup real compass thing, with event.alpha
} else {
// setup some mouse following hack
}这就足够了吗?我不太确定“有触摸支持但没有磁强计”的设备,例如mac笔记本上的铬有触摸支持,以及假的设备定位?
发布于 2014-02-28 14:21:54
它似乎起作用了,我错了,mac上的铬没有进入“真正的罗盘”部分。也许应该测试一下。
if (window.DeviceOrientationEvent && 'ontouchstart' in window) {
// setup real compass thing, with event.alpha
document.body.innerHTML = "haz!";
} else {
// setup some mouse following hack
document.body.innerHTML = "nope";
}检查自己:http://jsfiddle.net/benzkji/J58ef/
如果出现一个具有面向设备的chrome的启用触摸的windos笔记本电脑,会发生什么情况。可能会检查面向设备事件的“绝对”属性:orientation
https://stackoverflow.com/questions/18892719
复制相似问题