Home > Net >  JavaScript get version code in an HTML page with redirect
JavaScript get version code in an HTML page with redirect

Time:04-09

I would like to add this project in an html page, and after identifying the windows version redirect to a specified site.

Example: Windows 7 > siteX.com - Windows 10 > siteY.com

if(navigator.appVersion.indexOf("Windows ")!=-1){
    os = getWindowsOS();
}else{
    os = navigator.platform;
}

function getWindowsOS(){
    // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#PltToken
    if(navigator.appVersion.indexOf("Windows NT 10.")!=-1){
        return 'Windows 10';
    }else if(navigator.appVersion.indexOf("Windows NT 6.3")!=-1){
        return "Windows 8.1";
    }else if(navigator.appVersion.indexOf("Windows NT 6.2")!=-1){
        return "Windows 8";
    }else if(navigator.appVersion.indexOf("Windows NT 6.1")!=-1){
        return "Windows 7";
    }else if(navigator.appVersion.indexOf("Windows NT 6.0")!=-1){
        return "Windows Vista";
    }else if(navigator.appVersion.indexOf("Windows NT 5.2")!=-1){
        return "Windows Server 2003; Windows XP x64 Edition";
    }else if(navigator.appVersion.indexOf("Windows NT 5.1")!=-1){
        return "Windows XP";
    }else if(navigator.appVersion.indexOf("Windows NT 5.01")!=-1){
        return "Windows 2000, Service Pack 1 (SP1)";
    }else if(navigator.appVersion.indexOf("Windows NT 5.0")!=-1){
        return "Windows 2000";
    }else if(navigator.appVersion.indexOf("Windows NT 4.0")!=-1){
        return "Windows NT 4.0";
    }else if(navigator.appVersion.indexOf("Windows 98; Win 9x 4.90")!=-1){
        return "Windows Millennium Edition (Windows Me)";
    }else if(navigator.appVersion.indexOf("Windows 98")!=-1){
        return "Windows 98";
    }else if(navigator.appVersion.indexOf("Windows 95")!=-1){
        return "Windows 95";
    }else if(navigator.appVersion.indexOf("Windows CE")!=-1){
        return "Windows CE";
    }else{
        return "Windows OS, Version nicht bekannt";
    }
}

CodePudding user response:

Add your script to your html using a script tag:

<script>
// Detect OS:
let os;
if(navigator.appVersion.indexOf("Windows ")!=-1){
    os = getWindowsOS();
}else{
    os = navigator.platform;
}

function getWindowsOS(){
    // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#PltToken
    if(navigator.appVersion.indexOf("Windows NT 10.")!=-1){
        return 'Windows 10';
    }else if(navigator.appVersion.indexOf("Windows NT 6.3")!=-1){
        return "Windows 8.1";
    }else if(navigator.appVersion.indexOf("Windows NT 6.2")!=-1){
        return "Windows 8";
    }else if(navigator.appVersion.indexOf("Windows NT 6.1")!=-1){
        return "Windows 7";
    }else if(navigator.appVersion.indexOf("Windows NT 6.0")!=-1){
        return "Windows Vista";
    }else if(navigator.appVersion.indexOf("Windows NT 5.2")!=-1){
        return "Windows Server 2003; Windows XP x64 Edition";
    }else if(navigator.appVersion.indexOf("Windows NT 5.1")!=-1){
        return "Windows XP";
    }else if(navigator.appVersion.indexOf("Windows NT 5.01")!=-1){
        return "Windows 2000, Service Pack 1 (SP1)";
    }else if(navigator.appVersion.indexOf("Windows NT 5.0")!=-1){
        return "Windows 2000";
    }else if(navigator.appVersion.indexOf("Windows NT 4.0")!=-1){
        return "Windows NT 4.0";
    }else if(navigator.appVersion.indexOf("Windows 98; Win 9x 4.90")!=-1){
        return "Windows Millennium Edition (Windows Me)";
    }else if(navigator.appVersion.indexOf("Windows 98")!=-1){
        return "Windows 98";
    }else if(navigator.appVersion.indexOf("Windows 95")!=-1){
        return "Windows 95";
    }else if(navigator.appVersion.indexOf("Windows CE")!=-1){
        return "Windows CE";
    }else{
        return "Windows OS, Version nicht bekannt";
    }
}

// Redirect to specific site:
if (os === "Windows 7") {
    window.location = "https://siteX.com";
}

if (os === "Windows 10") {
    window.location = "https://siteY.com";
}
</script>
  • Related