js判断平台、系统、环境

const ua = window.navigator.userAgent;

/*系统*/
const system = {
    IOS: /(iPhone|iPad|iPod|iOS)/gi.test(ua),
    Android: /android|adr/gi.test(ua)
};

/*设备*/
const device = {
    IPAD: ua.match(/iPad/i) === "ipad",
    Mobile: /(iPhone|iPad|iPod|iOS|Android|adr|Windows Phone|SymbianOS)/gi.test(ua)
};

/*平台*/
const platform = {
    Wechat: /MicroMessenger/i.test(ua),
    WeMini: /(iPhone|iPad|iPod|iOS)/gi.test(ua)
        ? window.__wxjs_environment === "miniprogram"
        : /android|adr/gi.test(ua)
        ? /miniProgram/i.test(ua)
        : false,
    Aplipay: ua.indexOf("AlipayClient") > -1
};

你可能感兴趣的:(js判断平台、系统、环境)