1

I am creating an object to make it easier to access browser/system information by calling a function. One of those functions accesses the operating system name and version and returns a value.

const Sys = {
  // retrieves the operating system
  OS: function () {
    // function body
  }
  // other functions...
}

I don't know how to go about getting the information I need. I did find a similar question on Stack Overflow, but it didn't get the correct information. For example, if I am running on a Windows 10 Pro 32-bit, I want the output to be "Windows 10 Pro 32-bit". I'm guessing I have to use the navigator object, but other than that I really don't know anything else. Can anyone help with this?

ZzZzZzZz
  • 77
  • 1
  • 3
  • 9
  • Does this answer your question? [How to find the operating system version using JavaScript?](https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript) – Calvin Nunes Nov 23 '20 at 20:34
  • @CalvinNunes No, I tried using that solution but I didn't get all of the information, only some of it. – ZzZzZzZz Nov 23 '20 at 20:38
  • Does this answer your question? [Displaying the OS name/version and the browser name/version on the page?](https://stackoverflow.com/questions/7370200/displaying-the-os-name-version-and-the-browser-name-version-on-the-page) – lbragile Nov 23 '20 at 20:54

1 Answers1

0

I'd recommend using platform.js (see demo).

Identify user's browser:

platform.os;
// => OS X 10.15.6 (in my case)

Or parse a userAgent string.

let info = platform.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15");

info.name;
// => Safari

info.version;
// => 14.0.1

info.description;
// => Safari 14.0.1 on OS X 10.15.6
ΔO 'delta zero'
  • 3,506
  • 1
  • 19
  • 31