3

I'm working on a mobile site right now. But it performs a little bit different in a normal mobile browser and an in-app browser(when you scan the QR code or click a link in a social network app, for example). I use navigator.userAgent.match(/ipad|ipod|iphone|android/i) to detect mobile site and run corresponding javascript function, so I guess maybe this detection method doesn't work in in-app browser. Is there a universal way to detect all the mobile browsers including in-app one?

chaonextdoor
  • 5,019
  • 15
  • 44
  • 61
  • In-app browsers generally use the same browser framework that the stand-alone browser uses, with no reason to send anything to the host indicating a difference. You might be able to generate heuristics about screen sizes for the full size browsers and assume other sizes are an in-app browser, but this will not be accurate in all cases, especially Android in general. – mah May 14 '13 at 17:22
  • Try ("ontouchstart" in window && "onorientationchange" in window) – Samuli Hakoniemi May 14 '13 at 19:14
  • `navigator.userAgent.match(/android/)` will also detect mobile chrome browser which is not expected result. Every in-app browser have special string in their `userAgent`. For example, 'FBAV' for facebook, 'KAKAO' for kakaotalk. I think the optimal solution at this moment is that list up those special string for target in-app browsers. – Chemical Programmer Oct 28 '15 at 03:11

1 Answers1

2

There are user agent string variations even for in-app browsers. You can sometimes use those to detect specific in-app browsers: for instance, the Facebook on both iOS and Android contains the string FBAV (possibly short for Facebook Application Version?).

A working general solution for iOS is here: detect ipad/iphone webview via javascript

I'm not aware of a general solution for Android.

Community
  • 1
  • 1
pixelbandito
  • 480
  • 6
  • 12