javascript - Redirect based on operating system -


i'm new here , apologize if question basic/stupid. not familiar coding, please excuse ignorance/glaring errors. have tried put using code snippets found online , luckily don't have code project.

i trying automatically redirect users based on operating system , struggling making happen. here code trying use...assume know nothing!

<head> <script type="text/javascript"> <!-- var osname="unknown os"; if (navigator.appversion.indexof("win")!=-1) osname="windows"; if (navigator.appversion.indexof("mac")!=-1) osname="macos"; if (navigator.appversion.indexof("x11")!=-1) osname="unix"; if (navigator.appversion.indexof("linux")!=-1) osname="linux";  if( osname == "windows" ) {  window.location="http://www.driveweb.com/download-savvy-windows-free/"; } else if ( osname == "macos" ) { window.location="http://www.driveweb.com/download-savvy-mac-free/"; } else if ( osname == "unix" ) { window.location="http://www.driveweb.com/download-savvy-linux-free/"; } else if ( osname == "linux ) { window.location="http://www.driveweb.com/download-savvy-linux-free/"; } else { window.location="http://driveweb.com/download-savvy-select/"; } //--> </script> </head> 

thanks again, sincerely appreciate help!

use user agent instead, because appversion deprecated.

function detectos(){    if (navigator.useragent.indexof("win")!=-1) return "windows";    if (navigator.useragent.indexof("mac")!=-1) return "macos";    if (navigator.useragent.indexof("linux")!=-1) return "linux";    if (navigator.useragent.indexof("openbsd")!=-1) return "openbsd";    if (navigator.useragent.indexof("freebsd")!=-1) return "freebsd";    if (navigator.useragent.indexof("netbsd")!=-1) return "netbsd";    return undefined; } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -