Javascript iOS Chrome 检测
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13807810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Chrome detection
提问by cr1msaun
I use Javascript code
我使用 Javascript 代码
if( (Android|webOS|iPhone|iPad|iPod|BlackBerry).test(navigator.userAgent) ) {}
for mobile device detection, but Chrome at iOS is not detected. Is there a way to detect it? Thanks.
用于移动设备检测,但未检测到 iOS 上的 Chrome。有没有办法检测它?谢谢。
回答by Charlotte
According to Google Developers, the UA string looks like this:
根据Google Developers 的说法,UA 字符串如下所示:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3
Where it differs from iOS Safari in that it says CriOSinstead of Version. So this:
它与 iOS Safari 的不同之处在于它表示CriOS而不是Version. 所以这:
if(navigator.userAgent.match('CriOS'))
Should do it.
应该做。
回答by Chen_Wayne
if you want simple true/false answer:
如果你想要简单的真/假答案:
if(/CriOS/i.test(navigator.userAgent) &&
/iphone|ipod|ipad/i.test(navigator.userAgent)){
return true;
}else{
return false;
}
回答by Zarwalski
you can use 51Degrees' free cloud based solution to get this information. As part of the free cloud service you have access to the BrowserName property which includes Chrome for iOs.
您可以使用 51Degrees 基于云的免费解决方案来获取此信息。作为免费云服务的一部分,您可以访问包含 Chrome for iOs 的 BrowserName 属性。
Some sample code you could use is below. You can get the free cloud key by going through the store page here https://51degrees.com/products/store/rvdsfcatid/cloud-device-detection-7
您可以使用的一些示例代码如下。您可以通过此处的商店页面获取免费的云密钥https://51degrees.com/products/store/rvdsfcatid/cloud-device-detection-7
<!DOCTYPE html>
<html>
<body>
<p id="id01"></p>
<script>
var xmlhttp = new XMLHttpRequest();
<!-- Insert Cloud key here. -->
var key = "Licence Key"
<!-- Receives UserAgent from clients connection. -->
var ua = window.navigator.userAgent;
<!-- Lists the properties required. -->
var url = ("https://cloud.51degrees.com/api/v1/"+key+"/match?user-agent="+ua+"&Values=\
BrowserName");
<!-- Parses the JSON object from our cloud server and returns values. -->
xmlhttp.onreadystatechange = function(){
if ( xmlhttp.readyState == 4 && xmlhttp.status == 200){
var match = JSON.parse(xmlhttp.responseText);
var text = ""
document.getElementById("id01").innerHTML=\
"UserAgent:"+ua+"</br>"+
"BrowserName:"+match.Values.BrowserName;
}
}
<!-- Sends request to server. -->
xmlhttp.open("GET", url, true);
xmlhttp.send();
</script>
</body>
</html>
For more information on use of the JavaScript Cloud API you can view more tutorials here https://51degrees.com/Developers/Documentation/APIs/Cloud-API/JavaScript-Cloud
有关使用 JavaScript Cloud API 的更多信息,您可以在此处查看更多教程https://51degrees.com/Developers/Documentation/APIs/Cloud-API/JavaScript-Cloud
Disclosure: I work at 51Degrees
披露:我在 51Degrees 工作
回答by marcelo-ferraz
Perhaps, you could try:
或许,你可以试试:
var os = navigator.platform;
Then handle the os variable accordingly for your result.
然后根据您的结果相应地处理 os 变量。
You can also loop through each object of the navigator object to help get you more familiarized with the objects:
您还可以遍历导航器对象的每个对象,以帮助您更熟悉这些对象:
<script type="text/javascript">
for(var i in navigator){
document.write(i+"="+navigator[i]+'<br>');
}
</script>
As found in this anwser: jQuery/Javascript to detect OS without a plugin?
如在此 anwser 中发现的:jQuery/Javascript todetection OS without a plugin?

