Sometimes we may require operating system detection on client computer to take few several actions like redirect them to different landing page, save operating system to database along with other data for future references, allow visitors to download the suitable form of a software etc. However, there is no direct attribute where this is saved. But you will get the idea of the operating system from "navigator.appVersion". To identify correctly, you can use the following small code snippet easily:
function getOperatingSystemName(){
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";
return OSName;
}
this function will check the browsers navigator object to detect the correct operating system and will return the full name for easy reference. If it doesn't found the appropriate version from the four versions, then will return as 'Unknown OS'.
Subscribe to:
Post Comments (Atom)










1 comments:
that's all cool & great js tip, thank you very much for sharing.
Post a Comment