Chrome iOS Discovery

I am using javascript code

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

to detect mobile devices, but Chrome was not detected in iOS. Is there any way to detect this? Thank you

+29
javascript google-chrome ios mobile
Dec 10 '12 at 19:31
source share
4 answers

According to Google Developers , the UA string is as follows:

 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:

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

Must do it.

+79
Dec 10
source share

if you need a simple true / false answer:

 if(/CriOS/i.test(navigator.userAgent) && /iphone|ipod|ipad/i.test(navigator.userAgent)){ return true; }else{ return false; } 
+1
May 12 '16 at 5:51
source share

you can use 51Degrees free cloud solution to get this information. As part of the free cloud service, you have access to the BrowserName property, which includes Chrome for iOs.

Below is an example of code that you can use. You can get a free cloud key by going to 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 using the JavaScript cloud API, you can view more tutorials here https://51degrees.com/Developers/Documentation/APIs/Cloud-API/JavaScript-Cloud

Disclosure: I work for 51Degrees

0
Apr 12 '17 at 11:23 on
source share

Perhaps you could try:

 var os = navigator.platform; 

Then process the os variable accordingly for your result.

You can also scroll through each object of the navigator object to help you become more familiar with the objects:

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

As found in this address: jQuery / Javascript to detect an OS without a plugin?

-3
Dec 10 '12 at 19:35
source share



All Articles