Compilation of common front-end requirements - environment-related (judging Android/ios, judging WeChat environment)

Determine whether it is Android or iOS

Only consider the two cases of Android and ios

// 判断是安卓还是 ios
function checkDeviceType() {
    
    
  const u = navigator.userAgent;
  const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  if (isiOS) {
    
    
    terminalType.system = "ios";
  } else {
    
    
    terminalType.system = "andriod";
  }
}

Determine whether to open in WeChat

// 判断是否在微信中打开
function isWeChat() {
    
    
  const userAgent = navigator.userAgent.toLowerCase();
  return /MicroMessenger/i.test(userAgent)
}

Additional words

In the warehouse , it also provides a summary of many common front-end requirements and implementations. Guests are welcome to take a look~

If this note can help you, please help to highlight it on githubstar , thank you!

Guess you like

Origin blog.csdn.net/qq_61270298/article/details/129807226