Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oxmc/os-detect.js
A JavaScript function to help display what OS is accessing the page.
https://github.com/oxmc/os-detect.js
android browser ios javascript linux mac os-detection osx windows
Last synced: 3 days ago
JSON representation
A JavaScript function to help display what OS is accessing the page.
- Host: GitHub
- URL: https://github.com/oxmc/os-detect.js
- Owner: oxmc
- License: mit
- Created: 2021-06-17T06:09:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T09:36:41.000Z (2 months ago)
- Last Synced: 2024-11-05T10:34:07.826Z (2 months ago)
- Topics: android, browser, ios, javascript, linux, mac, os-detection, osx, windows
- Language: JavaScript
- Homepage: http://oxmc.is-a.dev/OS-Detect.js/
- Size: 103 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OS-Detect.js
A javascript function to help detect what OS is accessing the page.# Example
Here is a simple example# How to use
To use OS-Detect.js, first include the script in your head element:
```html
```
## Get OSDepending on what OS you want to detect change or modify this to fit your needs,
If you want to detect for windows:
```htmlasync function ShowOS() {
const OS = await DetectOS({debug: true});
if (OS.Type == "Windows") {
alert("OS is windows");
} else {
alert("OS is not windows");
};
};```
If you want to detect for Iphone, Ipad, or Ipod:
```htmlasync function ShowOS() {
const OS = await DetectOS({debug: true});
if (OS.ISIOS == "True") {
alert("OS is IOS");
} else {
alert("OS is not IOS");
};
};```
If you want to detect for MacOS:
```htmlasync function ShowOS() {
const OS = await DetectOS({debug: true});
if (OS.Type == "Mac") {
alert("OS is MacOS");
} else {
alert("OS is not MacOS");
};
};```
## Get OS VersionIf you want to detect the OS version:
```htmlasync function ShowOS() {
const OS = await DetectOS({debug: true});
/* Get OS name and version */
alert(`OS is: ${OS.Name} version: ${OS.Version}`);
};```
## Check if device is mobile:
```html
async function ShowOS() {
const OS = await DetectOS({debug: true});
/* Get OS name and version */
alert(`OS is: ${OS.Name} version: ${OS.Version} IsMobile: ${OS.IsMobile}`);
//In console:
/*
Debug set to true, printing OS info OS-Detect.min.js:1:5101
OS: Windows OS
Version: 10
IsMobile: False OS-Detect.min.js:1:5152
*/
};```
## Options:
OS-Detect only has 1 option as of now, debug: true or false
Prints the OS info in the console:
```htmlasync function ShowOS() {
const OS = await DetectOS({debug: true});
console.log(`OS: ${OS.Name}\nBrowser: ${OS.Browser}\nIsMobile: ${OS.IsMobile}`);
//In console:
/*
Debug set to true, printing OS info OS-Detect.min.js:1:5101
OS: Windows OS
Browser: Firefox 97
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0 OS-Detect.min.js:1:5152
*/
};```
## Detect OS without button or function call:You can use an async function like this:
```javascript
function ShowOSInfo(OS) {
console.log(`OS: ${OS.Name}\nBrowser: ${OS.Browser}\nUserAgent: ${OS.UserAgent}`);
};
(async () => {
var info = await DetectOS({debug: true});
console.log(info);
//Deal with info here, call function to handle data etc.
//function call:
ShowOSInfo(info);
})();
```