Pick up the Android version in the browser by Javascript

后端 未结 9 1262
小蘑菇
小蘑菇 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:59

    I made this function and worked very well in Android 2.6.3, 4.2.2., 6.0.1 in different browsers and devices. I think that can be an alternative.

    function check_android_version()
    {
        var ua = navigator.userAgent; 
        ua = ua.toLowerCase();
    
        var and_pos = ua.search("android");
        if(and_pos == -1)
            return 0; //not android
    
        var pv_pos = ua.indexOf(";", and_pos);
        var versao = ua.slice(and_pos+8, pv_pos);
    
        return versao;
    }
    

    This is quite simple, first, search for the word "android". If not found, returns 0 (is not an Android user agent). Then search for the first ';' after the "android" position that marks the end of the version. Once these positions are gotten, the 'slice' insulates the version numbers (that '+8' removes the word "android" of the final result) an then returns.

    If someone find any flaw, would be nice to share.

提交回复
热议问题