iOS Chrome detection

后端 未结 4 1493
情书的邮戳
情书的邮戳 2020-12-23 16:33

I use Javascript code

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

for mobile device detection, but Chrom

相关标签:
4条回答
  • 2020-12-23 16:51

    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.

    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

    <!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

    Disclosure: I work at 51Degrees

    0 讨论(0)
  • 2020-12-23 16:58

    Perhaps, you could try:

    var os = navigator.platform;
    

    Then handle the os variable accordingly for your result.

    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?

    0 讨论(0)
  • 2020-12-23 17:10

    According to Google Developers, the UA string looks like this:

    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 CriOS instead of Version. So this:

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

    Should do it.

    0 讨论(0)
  • 2020-12-23 17:11

    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;
    }
    
    0 讨论(0)
提交回复
热议问题