2.0.1 • Published 7 months ago
lesca-user-agent v2.0.1
Why use it?
Simple browser detection using the user agent.
Live Demo
Installation
npm install lesca-user-agent --save
Usage
location redirect
import UserAgent from 'lesca-user-agent';
if (UserAgent.get() === 'mobile') window.location.replace('./m/');
detect device
import UserAgent from 'lesca-user-agent';
const appIOS = 'https://apps.apple.com/us/app/github/id1477376905';
const appAndroid = 'https://play.google.com/store/apps/details?id=com.github.android';
function download() {
if (UserAgent.ios()) window.open(appIOS);
else window.open(appAndroid);
}
<button onClick={download}>download github</button>;
Development
Methods
method | description | default |
---|---|---|
.get(tabletEqualDesktop:boolean):string | get user device | false |
.facebook():boolean | is facebook browser | |
.line():boolean | is Line browser | |
.ios():boolean | is Ios browser | |
.android():boolean | is Android browser | |
.mac():boolean | is Mac browser | |
.pc():boolean | is PC browser |
Features
- maintain if necessary