2

I know how to detect chrome on iOS using navigator.userAgent.match('CriOS') but what i need to be able to do is to target chrome on any mobile device, and i'm having trouble doing this reliably.

Any ideas on how to do this consistently are really gratefully accepted!

John
  • 833
  • 1
  • 11
  • 24
  • are you looking for [detect chrome](http://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome)? – Venugopal Jan 12 '16 at 13:53

2 Answers2

0

Try checking for webkit at an object property

if ("WebkitTouchCallout" in document.body.style) {
  // do stuff
}

See List of Webkit CSS Properties for Mobiles

guest271314
  • 1
  • 15
  • 104
  • 177
  • Is that a mobile only property? – John Jan 12 '16 at 13:46
  • _"Is that a mobile only property?"_ No. – guest271314 Jan 12 '16 at 13:47
  • Then how is that detecting chrome on mobile only? – John Jan 12 '16 at 13:49
  • @John See updated post. Could substitute `WebKitOverflowScrolling` or `WebkitTouchCallout` for `WebkitAnimation` if requirement is only mobile properties – guest271314 Jan 12 '16 at 13:51
  • @John Tried `WebkitOverflowScrolling` , `WebkitTapHighlightColor` ? – guest271314 Jan 12 '16 at 14:03
  • Yes but they are not exclusive to mobile. – John Jan 12 '16 at 14:04
  • @John _"Yes but they are not exclusive to mobile"_ ? `WebkitOverflowScrolling` and `WebkitTapHighlightColor` do not appear as properties of `style` , here, at non-mobile chrome – guest271314 Jan 12 '16 at 14:08
  • @John Not certain which of these properties is mobile-only, though should be able to filter through, or try them, and use `for..in` to check using same approach at Answer https://developer.mozilla.org/en-US/docs/Web/CSS/Webkit_Extensions , https://gist.github.com/afabbro/3759334 – guest271314 Jan 12 '16 at 14:14
-1
 if (navigator.userAgent.indexOf("Chrome") != -1) {
   alert('Chrome');
 }

Demo:

https://jsfiddle.net/ngn4L2hx/

UPDATE:

if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
  alert("Chrome");
}

Demo:

https://jsfiddle.net/oe4yh480/1/

Ray Joe
  • 182
  • 1
  • 2
  • 11