フロントエンド共通要件の取りまとめ - 環境関連(Android/iOSの判断、WeChat環境の判断)

AndroidかiOSかを判断する

Android と iOS の 2 つのケースのみを考慮してください

// 判断是安卓还是 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";
  }
}

WeChat で開くかどうかを決定する

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

追加の言葉

ウェアハウスでは、多くの一般的なフロントエンド要件と実装の概要も提供されています。

このメモが役立つ場合は、githubでハイライトするのにご協力くださいstar。ありがとうございます。

おすすめ

転載: blog.csdn.net/qq_61270298/article/details/129807226