Pick up the Android version in the browser by Javascript

后端 未结 9 1233
小蘑菇
小蘑菇 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 05:56

    1- Windows phone introduced a fake "android" user agent, so this deal with it
    2- As @andy pointed out, there are some models with this format: Android/#.##
    3- You can use the flag /i for case-insensitive
    4- This code gives you back NaN when its not android and the version as a float when it is.
    5- If you find more fake android phones you only need to add the string like this: (?:windows phone|fake phone|android...........

    alert( parseFloat(navigator.userAgent.match(/.*?(?:windows phone|android\D+([0-9\.]*))|()/i)[1]) );

提交回复
热议问题