Pick up the Android version in the browser by Javascript

后端 未结 9 1236
小蘑菇
小蘑菇 2020-12-02 05:09

I\'m building a web app and wanting to disable transitions effects on Android devices under version 3.0.

Is there anyway to pick up the Android version number by Ja

9条回答
  •  失恋的感觉
    2020-12-02 06:06

    You can look at the user agent string - window.navigator.userAgent described here: https://developer.mozilla.org/en/DOM/window.navigator.userAgent

    If what you're really trying to detect is whether you have a version of the browser that supports a particular feature, then it's nearly always better to use feature detection instead of browser version detection. modernizr is a huge base of code for feature detection that you can either use as is or borrow one particular piece from or just learn how the general technique works.

    When I Google, I see user agent strings like this for Android:

    Mozilla/5.0 (Linux; U; Android 2.2.1; fr-ch; A43 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
    

    A regex of /Android\s+([\d\.]+)/ on window.navigator.userAgent will pick up the Android version number.

提交回复
热议问题