jQuery - detecting the operating system and operating system version

前端 未结 3 1453
灰色年华
灰色年华 2020-12-08 12:40

I have been writing a userscript for the past few months, for my company, and have just designed the main site for it with installation instructions (our employees are based

相关标签:
3条回答
  • 2020-12-08 12:48

    The Stack Overflow question Detect exact OS version from browser goes into some interesting detail about getting the OS version from the User-Agent header which I believe contains the same information that can be accessed from JavaScript.

    0 讨论(0)
  • 2020-12-08 12:56

    You can use this great javascript library: http://www.visitorjs.com/details It is open-sourced recently

    Edit: Actually, it is now renamed to session.js http://github.com/codejoust/session.js and to my knowledge, that is the best you can get.

    0 讨论(0)
  • 2020-12-08 13:01

    Your best bet is to use the navigator.userAgent property. It will give the windows version number. You can see a table of how the Windows version number map to the OS here:

    OSVERSIONINFO

    Here is some example detection code:

    var os = (function() {
        var ua = navigator.userAgent.toLowerCase();
        return {
            isWin2K: /windows nt 5.0/.test(ua),
            isXP: /windows nt 5.1/.test(ua),
            isVista: /windows nt 6.0/.test(ua),
            isWin7: /windows nt 6.1/.test(ua),
            isWin8: /windows nt 6.2/.test(ua),
            isWin81: /windows nt 6.3/.test(ua)
        };
    }());
    
    if(os.isWin7) {
        ...
    }
    

    http://jsfiddle.net/45jEc/

    0 讨论(0)
提交回复
热议问题