最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to detect an in-app browser in iphone and android? - Stack Overflow

programmeradmin2浏览0评论

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?

Share Improve this question asked May 14, 2013 at 17:20 chaonextdoorchaonextdoor 5,14915 gold badges50 silver badges63 bronze badges 3
  • 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 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 Commented Oct 28, 2015 at 3:11
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论