In order to detect the operating system on the client machine, the navigator.appVersionstring (property) should be used.
To detect the operating system on the client machine in web development, you can use JavaScript. Here’s a way to achieve this:
var operatingSystem = "Unknown OS";
if (navigator.appVersion.indexOf("Win") != -1) operatingSystem = "Windows";
if (navigator.appVersion.indexOf("Mac") != -1) operatingSystem = "MacOS";
if (navigator.appVersion.indexOf("Linux") != -1) operatingSystem = "Linux";
if (navigator.appVersion.indexOf("Android") != -1) operatingSystem = "Android";
if (navigator.appVersion.indexOf("iOS") != -1) operatingSystem = "iOS";
console.log("Operating System: " + operatingSystem);
This code checks the navigator.appVersion
property to determine the operating system based on the presence of certain keywords like “Win” for Windows, “Mac” for MacOS, “Linux” for Linux, “Android” for Android OS, and “iOS” for iOS.
Remember, this method relies on the user agent string provided by the browser, which can be spoofed or modified. So, it may not always be 100% accurate.