How does js prepare to judge useragent information?

for example, my website is divided into
pc www.mysite.com
Mobile m.mysite.com

I want to realize that when a user browses my pc version of www.mysite.com through a mobile device, it can determine whether the user is browsing on a mobile device through js, and transfer to the corresponding mobile version of m.mysite.com

.

how to write this js, is there any mature plug-in and so on? please advise, thank you!

Mar.11,2022

/**
 * 
 * @returns {boolean}
 */
const isMobile = () => {
  const u = navigator.userAgent,
    mobile = !!u.match(/AppleWebKit.*Mobile.*/), //
    ios = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
    android = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //androiduc
    iPhone = u.indexOf('iPhone') > -1, //iPhoneQQHD
    iPad = u.indexOf('iPad') > -1; //iPad

  return mobile || ios || android || iPhone || iPad;
};

/**
 * 
 * @returns {boolean}
 */
const isWechat = () => {
  const ua = navigator.userAgent.toLowerCase();
  return ua.match(/MicroMessenger/i) == 'micromessenger';
};

Mobile judgment function I am currently using




var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;//
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);//ios
// 
    function is_weixn() {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    }
    //PC
    function IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; vPP) {
            if (userAgentInfo.indexOf(Agents[v]) >= 0) {
                flag = false;
                break;
            }
        }
        return flag;
    }


js useragent


try this?
https://github.com/fex-team/u.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eace48-46b92.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eace48-46b92.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?