52

Javascriptコードを使用しています

if( (Android|webOS|iPhone|iPad|iPod|BlackBerry).test(navigator.userAgent) ) {}

モバイルデバイスの検出用ですが、iOSのChromeは検出されません。それを検出する方法はありますか?ありがとう。

4

4 に答える 4

134

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

CriOSの代わりに言うという点でiOSSafariと異なるところVersion。したがって、この:

if(navigator.userAgent.match('CriOS'))

それをする必要があります。

于 2012-12-10T19:48:11.210 に答える
15

単純な真/偽の答えが必要な場合:

if(/CriOS/i.test(navigator.userAgent) &&
/iphone|ipod|ipad/i.test(navigator.userAgent)){
    return true;
}else{
    return false;
}
于 2016-05-12T05:51:00.427 に答える
-3

おそらく、あなたは試すことができます:

var os = navigator.platform;

次に、結果に応じてos変数を処理します。

ナビゲーターオブジェクトの各オブジェクトをループして、オブジェクトに慣れることもできます。

<script type="text/javascript">
for(var i in navigator){
    document.write(i+"="+navigator[i]+'<br>');
}
</script>

この回答にあるように: プラグインなしでOSを検出するjQuery / Javascript?

于 2012-12-10T19:35:20.763 に答える
-3

51Degreesの無料のクラウドベースのソリューションを使用して、この情報を取得できます。無料のクラウドサービスの一部として、ChromeforiOsを含むBrowserNameプロパティにアクセスできます。

使用できるサンプルコードを以下に示します。こちらのストアページから無料のクラウドキーを入手できます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>

JavaScript Cloud APIの使用の詳細については、https://51degrees.com/Developers/Documentation/APIs/Cloud-API/JavaScript-Cloudで他のチュートリアルを表示できます。

開示:私は51度で働いています

于 2017-04-12T11:23:25.520 に答える