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?
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?
- 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 Commented May 14, 2013 at 17:22
- Try ("ontouchstart" in window && "onorientationchange" in window) – Samuli Hakoniemi Commented May 14, 2013 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 theiruserAgent
. 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 Commented Oct 28, 2015 at 3:11
1 Answer
Reset to default 2There 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.