JavaScript的:确定它是否是一个桌面Linux或Android [英] Javascript : Identify whether it is a desktop Linux or Android
问题描述
无法确定它是否是一个Linux桌面机或者使用的navigator.userAgent
Android设备或 navigator.platform
如一些Android设备的有两个字符串的Linux
。详情如下
Unable to identify whether it is a linux desktop machine or an android device using navigator.userAgent
or navigator.platform
as some android device's have the string linux
in both. Details follows
Device OS navigator.platform
--------------------------------------------------------------------
Samsung Galaxy S3 Android 4.3 Linux armv7l
HTC One Android 4.4.2 Linux armv7l
Sony Xperia Z Android 4.2.2 Linux armv7l
Motorola Moto G Android 4.4.2 Linux armv7l
Samsung Galaxy Tab 3 Android 4.2.2 Linux i686
Nexus 10 Android 4.4.2 Linux armv7l
Lenovo Yoga Android 4.2.2 Linux armv7l
的navigator.userAgent
Mozilla/5.0 (Linux; U; Android 2.2; en-us; SCH-I800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
即使我试图触摸事件,但Linux桌面可以触摸,也可以模拟触摸。请大家帮忙
Even I tried with touch events, but linux desktop can have touch or it can emulate touch. please help
更新:解决方案应该检测的Linux即使桌面浏览器的摸拟设备被激活。 <一href=\"http://stackoverflow.com/questions/8068052/phonegap-detect-if-running-on-desktop-browser/29818615#29818615\">View详情
Update: The solution should detect Linux even if Desktop browser's emulate device is active. View Details
推荐答案
您可以试试这个:
if (navigator.userAgent.match(/linux/i) && navigator.userAgent.match(/android/i)) {
// it's andorid
} else if (navigator.userAgent.match(/linux/i)) {
// it's linux
}
这篇关于JavaScript的:确定它是否是一个桌面Linux或Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!