admin管理员组文章数量:1389355
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.
本文标签: javascriptHow to detect an inapp browser in iphone and androidStack Overflow
版权声明:本文标题:javascript - How to detect an in-app browser in iphone and android? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744645376a2617370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论