通过浏览器检查手机端PC端

通过浏览器检查手机端PC端

const checkPlatform = function () {
    let nowPF = 'mobile';
    let sys = 'ADK';
    let ua = navigator.userAgent;
    if (/iPad|iPhone|iPod/i.test(ua)) {
        nowPF = 'mobile';
        sys = 'IOS';
    } else if (/Android|webOS|BlackBerry|HarmonyOS/i.test(ua)) {
        nowPF = 'mobile';
        sys = 'ADK';
    } else {
        nowPF = 'pc';
        sys = 'MS';
    }
    ua = ua.toLocaleLowerCase();
    let ver = ua.match(/cpu iphone os(.*?) like mac os/);
    let nowVer;
    if (!ver) {
        nowVer = '';
    } else {
        nowVer = ver[1].replace(/_/g, ".");
    }
    let iswx;
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        iswx = true;
    } else {
        iswx = false;
    }
    return { pf: nowPF, sys: sys, ver: nowVer, wx: iswx };
}
export { checkPlatform };

你可能感兴趣的:(通过浏览器检查手机端PC端)