How to detect my browser version and operating system using JavaScript?

后端 未结 10 1138
天命终不由人
天命终不由人 2020-11-22 06:25

I have tried using the code below but it only display results in Chrome and Mozilla not working in IE6.

10条回答
  •  情书的邮戳
    2020-11-22 07:04

    Try this one..

    // Browser with version  Detection
    navigator.sayswho= (function(){
        var N= navigator.appName, ua= navigator.userAgent, tem;
        var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\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;
    })();
    
    var browser_version          = navigator.sayswho;
    alert("Welcome to " + browser_version);
    

    check out the working fiddle ( here )

提交回复
热议问题