How can you detect the version of a browser?

后端 未结 28 2626
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:35

I\'ve been searching around for code that would let me detect if the user visiting the website has Firefox 3 or 4. All I have found is code to detect the type of browser but

28条回答
  •  耶瑟儿~
    2020-11-22 00:27

    function BrowserCheck()
    {
        var N= navigator.appName, ua= navigator.userAgent, tem;
        var M= ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i);
        if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) {M[2]=tem[1];}
        M= M? [M[1], M[2]]: [N, navigator.appVersion,'-?'];
        return M;
    }
    

    This will return an array, first element is the browser name, second element is the complete version number in string format.

提交回复
热议问题