iOS Chrome detection

JavascriptIosGoogle ChromeMobile

Javascript Problem Overview


I use Javascript code

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.

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

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;
}

Solution 3 - Javascript

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: https://stackoverflow.com/questions/7044944/jquery-javascript-to-detect-os-without-a-plugin

Solution 4 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioncr1msaunView Question on Stackoverflow
Solution 1 - JavascriptBellaView Answer on Stackoverflow
Solution 2 - JavascriptChen_WayneView Answer on Stackoverflow
Solution 3 - Javascriptmarcelo-ferrazView Answer on Stackoverflow
Solution 4 - JavascriptZarwalskiView Answer on Stackoverflow