我正在寻找使用纯 JS 检测 webOS 平板电脑的最佳方法,如果使用 jQuery 更容易的话。平板电脑的用户代理应该看起来像这样:
User-Agent:Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Desktop/1.0
所以一个简单的方法是:
var deviceAgent = navigator.userAgent.toLowerCase();
webOS = deviceAgent.match(/(webos)/);
这是最好的方法吗?您可能会说检测您需要确定的功能是否存在,但这对我不起作用,因为我想要的功能存在,但无法像在任何桌面上那样工作,所以我真的只想知道是这是否是一个 webOS 设备。
更新:刚刚发现平板电脑确实使用了另一个用户代理:
Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; xx-xx) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.48 Safari/534.6 TouchPad/1.0
所以上面的内容可能应该是:
var deviceAgent = navigator.userAgent.toLowerCase();
webOS = deviceAgent.match(/(webos|hpwos)/);
I'm looking for the best way to detect a webOS tablet using plain JS and if it's any easier also using jQuery. The user agent of the tablet should look something like this:
User-Agent:Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Desktop/1.0
So an easy way would be:
var deviceAgent = navigator.userAgent.toLowerCase();
webOS = deviceAgent.match(/(webos)/);
Is that the best way to do it already? You're likely going to say detect the feature you need to make certain is present but that won't work for me because the feature I want is present but not working as it would on any desktop, so I really just want to know is this a webOS device or not.
Update: Just found that the tablet really uses another user agent:
Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; xx-xx) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.48 Safari/534.6 TouchPad/1.0
So the above should probably rather be:
var deviceAgent = navigator.userAgent.toLowerCase();
webOS = deviceAgent.match(/(webos|hpwos)/);
发布评论
评论(2)
这是 PHP 中的一个函数,可以检测 WebOS 和您可能需要的任何其他移动设备。代码小于 1kb =)
如果您只想执行 webOS,请将第 2 行更改为:
要使用:
如果您需要更多详细信息,请访问此处:http://www.justindocanto.com/scripts/detect-a-mobile-device-in-php-using-detectmobiledevice
Here's a function in PHP that will detect WebOS and any other mobile device you could need. Less than 1kb in code =)
if you want to do ONLY webOS, change line 2 to:
to use:
if you need more details, visit here: http://www.justindocanto.com/scripts/detect-a-mobile-device-in-php-using-detectmobiledevice
我不知道你是否可以进行任何只能识别 WebOS 的功能检测。它基于 WebKit,因此所有其他基于 WebKit 的平台都将具有相同的功能。查看 Zepto.js' 源代码,他们的做法与您完全相同:(
第二次捕获是版本)
来自 detect.js
I don't know if you can do any feature detection that'll only identify WebOS. It's WebKit-based, so all other WebKit-based platforms will have the same features. Looking at Zepto.js' source, they're doing exactly the same as you are:
(The 2nd capture is the version)
From detect.js