Simple check of operating system from HTML / JS

I saw some questions about using JS to get detailed OS information. But I just want to know if I am on Windows or not. My browser plugin will first support Windows, so I don’t want users to aimlessly download the EXE / MSI installer.

I thought you could do something like this without using JS ... I saw strange conditional HTML code to detect IE in old IIRC books.

+3
source share
3 answers

You can create a hidden download link and an alternative stylesheet for your site and switch between them using conditional comments:

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->

And in this stylesheet, regular browsers see this:

#download
{
  display: none;
}

ie.css :

#download
{
  display: block !important;
}

JavaScript, :

if (navigator.appVersion.indexOf('Win') != -1 && /MSIE (\d+\.\d+);/.test(navigator.userAgent))
{
  var version = new Number(RegExp.$1);

  if (version > 7)
  {
    alert('You are using a compatible browser.');
  }
}

Chrome Linux, ( , ).

+3
+2

javascript, , , IE , , / javascript css.

If you really want to know the OS, browser, etc., you can try parsing the user-agent string. It reports a browser, operating system, and other values, but is not reliable (for example, you can fake a string). Quirksmode has a nice feature for detecting browser and OS.

0
source

Source: https://habr.com/ru/post/1796089/


All Articles