UA-detect
Description
The dead-simple way of detecting a device's user agent.
Technologies Used
Installation
via npm
Install the uadetect
package
npm i -d uadetect
In a JavaScript (or TypeScript) file, import the uadetect
module:
import { DetectScreenOrientation, DetectDeviceType, finiteMobileDeviceType, ORIENTATION_isLandscape, DEVICE_type, DEVICE_finiteType } from 'uadetect';
All done. Now you can use the ORIENTATION_isLandscape
, DEVICE_finiteType
and DEVICE_type
constraints in your code.
Usage
function hideOnMobile(element) {
if (DEVICE_type == "mobile") {
element.style.display = "none";
}
}
function showOnOS(element, element2) {
if (DEVICE_finiteType == "iOS") {
element.style.display = "block";
}
else if (DEVICE_finiteType == "Android") {
element2.style.display = "block";
}
else {
element.style.display = "none";
element2.style.display = "none";
}
}