私は、モバイルデバイスの検出のためのJavascriptコードiOS版Chromeが検出
if((Android|webOS|iPhone|iPad|iPod|BlackBerry).test(navigator.userAgent)) {}
を使用していますが、iOS版のクロムが検出されていません。それを検出する方法はありますか?おかげさまで
私は、モバイルデバイスの検出のためのJavascriptコードiOS版Chromeが検出
if((Android|webOS|iPhone|iPad|iPod|BlackBerry).test(navigator.userAgent)) {}
を使用していますが、iOS版のクロムが検出されていません。それを検出する方法はありますか?おかげさまで
よる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
ここでは、iOS Safariとは異なり、の代わりにしたがって、これは:
if(navigator.userAgent.match('CriOS'))
する必要があります。
おそらく、あなたが試みることができる:
var os = navigator.platform;
は、その後、あなたの結果のためにそれに応じてOSの変数を扱います。
また、navigatorオブジェクトの各オブジェクトをループを使用すると、複数のオブジェクトに慣れ得るためにすることができます
<script type="text/javascript">
for(var i in navigator){
document.write(i+"="+navigator[i]+'<br>');
}
</script>
このanwserで見たよう: jQuery/Javascript to detect OS without a plugin?
これは、iOS上のChromeアプリを検出しているOPによって概説されている特定のシナリオを解決しません。 –
あなたは、単純な真/偽の答えをしたい場合:
if(/CriOS/i.test(navigator.userAgent) &&
/iphone|ipod|ipad/i.test(navigator.userAgent)){
return true;
}else{
return false;
}
あなたがこの情報を取得するために51Degrees'無料のクラウドベースのソリューションを使用することができます。無料クラウドサービスの一環として、Chrome for iOSを含むBrowserNameプロパティにアクセスできます。
使用できるサンプルコードは以下のとおりです。私は51Degrees
で働く:あなたはより多くのここのチュートリアル https://51degrees.com/Developers/Documentation/APIs/Cloud-API/JavaScript-Cloud開示を表示することができますJavaScriptのクラウドAPIの使用方法の詳細についてはこちらを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>
ストアページを経由することにより、無料のクラウドキーを取得することができます
なぜこれを行う必要がありますか? – Blender
私はデスクトップ上でしか見えない特殊な視覚効果のためにこれを必要とします – cr1msaun
ブラウザがタッチサポートを持っているかどうかを検出し、クラスを 'body'要素に適用します。 Modernizrはこれを行います。 – Blender