How to detect client OS in Javascript

To detect client OS in Javascript you can use the following snippet.

Sample JS

function getOS() {

    if (navigator.appVersion.indexOf("Windows NT 6.3") != -1) {
        return "Windows 8.1";
    }

    if (navigator.appVersion.indexOf("Windows NT 6.2") != -1) {
        return "Windows 8";
    }

    if (navigator.appVersion.indexOf("Windows NT 6.1") != -1) {
        return "Windows 7";
    }

    if (navigator.appVersion.indexOf("Windows NT 6.0") != -1) {
        return "Windows Vista";
    }

    if (navigator.appVersion.indexOf("Windows NT 5.1") != -1) {
        return "Windows XP";
    }

    if (navigator.appVersion.indexOf("Windows NT 5.0") != -1) {
        return "Windows 2000";
    }

    if (navigator.appVersion.indexOf("Windows NT 4.0") != -1) {
        return "Windows NT 4.0";
    }

    if (navigator.appVersion.indexOf("Windows NT 3.51") != -1) {
        return "Windows NT 3.51";
    }

    if (navigator.appVersion.indexOf("Windows NT 3.5") != -1) {
        return "Windows NT 3.5";
    }

    if (navigator.appVersion.indexOf("Windows NT 3.1") != -1) {
        return "Windows NT 3.1";
    }

    if (navigator.appVersion.indexOf("Windows ME") != -1) {
        return "Windows ME";
    }

    if (navigator.appVersion.indexOf("Windows 98") != -1 || navigator.appVersion.indexOf("Win98") != -1) {
        return "Windows 98";
    }
    if (navigator.appVersion.indexOf("Windows 95") != -1 || navigator.appVersion.indexOf("Win95") != -1 || navigator.appVersion.indexOf("Windows_95") != -1) {
        return "Windows 95";
    }

    if (navigator.appVersion.indexOf("Win16") != -1) {
        return "Windows 3.11";
    }

    if (navigator.appVersion.indexOf("Mac_PowerPC") != -1 || navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("Macintosh") != -1) {
        return "Mac/iOS";
    }
    if (navigator.appVersion.indexOf("OpenBSD") != -1) {
        return "OpenBSD";
    }

    if (navigator.appVersion.indexOf("QNX") != -1) {
        return "QNX";
    }

    if (navigator.appVersion.indexOf("BeOS") != -1) {
        return "BeOS";
    }

    if (navigator.appVersion.indexOf("BeOS") != -1) {
        return "BeOS";
    }

    if (navigator.appVersion.indexOf("SunOS") != -1) {
        return "SunOS";
    }

    if (navigator.appVersion.indexOf("OS/2") != -1) {
        return "OS/2";
    }

    if (navigator.appVersion.indexOf("Linux") != -1) {
        return "Linux";
    }

    if (navigator.appVersion.indexOf("nuhk") != -1 || navigator.appVersion.indexOf("Googlebot") != -1 || navigator.appVersion.indexOf("Yammybot") != -1 || navigator.appVersion.indexOf("Openbot") != -1 || navigator.appVersion.indexOf("Slurp") != -1 || navigator.appVersion.indexOf("MSNBot") != -1 || navigator.appVersion.indexOf("Ask Jeeves/Teoma") != -1 || navigator.appVersion.indexOf("ia_archiver") != -1){
        return "Search Bot";
    }
    return "Unknown OS";
}

Please Share us:
Please rate this snippet

2 thoughts on “How to detect client OS in Javascript

Leave a Reply