How to detect the stock Android browser

前端 未结 14 1958
不思量自难忘°
不思量自难忘° 2020-12-08 01:52

Navigating to http://whatsmyuseragent.com/ shows me my stock Android browser on my Galaxy Nexus running 4.2.1 has the user agent

Mozilla/5.0 (X11; Linux x86_         


        
14条回答
  •  我在风中等你
    2020-12-08 02:38

    If JavaScript instead of server-side UA sniffing is an option for you, try (!!window.chrome) && (!window.chrome.app). I can't guarantee, however, that this one is "safe", will work "forever", or something like that. Consider it an evil hack to be used for testing purposes only.

    Explanation: Chrome (or Chromium?) Browsers (well, the ones I tested here, which were Chrome and Android stock on Cyanogenmod 10) have an object named window.chrome, but on the Android stock browser, the one I tested at least, this object does not have the app property.

    Edit: Seems like older Chrome versions will give false positives with this solution. In turn, newer versions of the stock browser will most likely give "false negatives".

提交回复
热议问题