什么是 iOS 5.0 用户代理字符串?
这是 iOS 4.0 用户代理:What is the iPhone 4 user-agent?
苹果手机:
Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3
平板电脑:
Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3
该网站似乎keep a complete list that's still maintained
iOS 2.0 - 5.1.1(迄今为止)的 iPhone、iPod Touch 和 iPad。
您确实需要从页面列中列出的信息中组装完整的用户代理字符串。
我在 user agent string 找到了更完整的列表。顺便说一句,这个网站不仅仅是 iOS 用户代理字符串。此外,主页将为您“分解”当前浏览器的用户代理字符串。
通过擦除 LOWERCASE“iphone os 5_0”而不是“iPhone OS 5_0”的字符串来修复我的代理字符串评估。现在,当大写擦除失败时,我正在正确地将 iOS 5 特定类分配给我的 html。
我使用以下内容来检测不同的移动设备、视口和屏幕。对我来说效果很好,可能对其他人有帮助:
var pixelRatio = window.devicePixelRatio || 1;
var viewport = {
width: window.innerWidth,
height: window.innerHeight
};
var screen = {
width: window.screen.availWidth * pixelRatio,
height: window.screen.availHeight * pixelRatio
};
var iPhone = /iPhone/i.test(navigator.userAgent);
var iPhone4 = (iPhone && pixelRatio == 2);
var iPhone5 = /iPhone OS 5_0/i.test(navigator.userAgent);
var iPad = /iPad/i.test(navigator.userAgent);
var android = /android/i.test(navigator.userAgent);
var webos = /hpwos/i.test(navigator.userAgent);
var iOS = iPhone || iPad;
var mobile = iOS || android || webos;
window.devicePixelRatio
是设备上的物理像素和与设备无关的像素(下降)之间的比率。 window.devicePixelRatio
= 物理像素/下降。
更多信息here。
var iOS5 = /(iPhone|iPad).*OS 5_.*/i.test(navigator.userAgent);
这样的正则表达式
不定期副业成功案例分享