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

后端 未结 10 1074
天命终不由人
天命终不由人 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:10

    PPK's script is THE authority for this kind of things, as @Jalpesh said, this might point you in the right way

    var wn = window.navigator,
            platform = wn.platform.toString().toLowerCase(),
            userAgent = wn.userAgent.toLowerCase(),
            storedName;
    
    // ie
        if (userAgent.indexOf('msie',0) !== -1) {
            browserName = 'ie';
            os = 'win';
            storedName = userAgent.match(/msie[ ]\d{1}/).toString();
            version = storedName.replace(/msie[ ]/,'');
    
            browserOsVersion = browserName + version;
        }
    

    Taken from https://github.com/leopic/jquery.detectBrowser.js/blob/sans-jquery/jquery.detectBrowser.sansjQuery.js

提交回复
热议问题