前端判断当前浏览器是否为 Chrome

悠扬的幻想天空 - 博客

April 7, 2022 技术 • 作者:悠扬

// 判断是否为谷歌浏览器
export const isChrome = () => {
  const ua = navigator?.userAgent.toLocaleLowerCase();
  if (ua) {
    if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
      return false; // QQ 浏览器
    }
  }
  const isChromium = window?.chrome;
  const winNav = window.navigator;
  const vendorName = winNav.vendor;
  const isOpera = typeof window?.opr !== 'undefined';
  const isIEedge = winNav.userAgent.indexOf('Edge') > -1;
  const isIOSChrome = winNav.userAgent.match('CriOS');

  return (
    isIOSChrome ||
    (isChromium !== null &&
      typeof isChromium !== 'undefined' &&
      vendorName === 'Google Inc.' &&
      isOpera === false &&
      isIEedge === false)
  );
};

已有 3 条评论

  1. 叼茂SEO.bfbikes.com

  2. 叼茂SEO.bfbikes.com

  3. 想想你的文章写的特别好https://www.237fa.com/

添加新评论