useragent.js Module Documentation

Bahasa Indonesia

useragent.js contains one function that guesses whether the page is opened on a mobile device, by matching navigator.userAgent against a regex. No third-party library is involved.

Usage (Import)

import { isMobile } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/useragent.js";

isMobile()

Returns true if navigator.userAgent contains any of Android, webOS, iPhone, iPad, iPod, BlackBerry, IEMobile, or Opera Mini (case-insensitive), and false otherwise. Takes no parameters.

import { isMobile } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/useragent.js";
import { show, hide } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/element.js";

if (isMobile()) {
    show("open-app-button");
    hide("desktop-download-button");
}

Notes