How can I find the OS name and OS version using JavaScript?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
JavaScript have access to the
window.navigator.platform
- a string representing the platform of the browser: https://developer.mozilla.org/en/DOM/window.navigator.platformUse it to extract whatever details you need (and can). Note that there are no guarantees that the client actually uses that platform since this can easily be modified in many ways.
If you list all of
window.navigator
's properties usingYou'll see something like this
Note that
oscpu
attribute gives you the Windows version. Also, you should know that:You can use this
javascript
function to check users' OS simplyplatform.js seems like a good one file library to do this.
Usage example:
Use detectOS.js:
Hey for a quick solution you can consider the following library : UAPARSER - https://www.npmjs.com/package/ua-parser-js
example :
you can also install the library via npm, and import it like this:
the library is a JS based user agent string parser (window.navigator.userAgent is the user agent on browser) , so you can get with it other details aswell such as Browser,device,engines etc..and it can work with node js as well.
if you need typing for the library : https://www.npmjs.com/package/@types/ua-parser-js