基于javascript实现检测浏览器名称和版本参数信息

所属分类: 网页特效-实用工具    2023-12-10 11:57:29

基于javascript实现检测浏览器名称和版本参数信息 ie兼容6
反馈问题  查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

基于javascript实现检测浏览器名称和版本参数信息(共3个文件)

    • index.html

使用方法

function detectIosVersion() {
  if (/iP(hone|od|ad)/.test(navigator.platform)) {
    var v = navigator.appVersion.match(/OS (\\d+)_(\\d+)_?(\\d+)?/);

    const result = [
      parseInt(v[1], 10),
      parseInt(v[2], 10),
      parseInt(v[3] || 0, 10)
    ].join(".");

    return result;
  }

  return "-";
}

function detectAppleOs() {
  if (/Safari[\\/\\s](\\d+\\.\\d+)/.test(window.navigator.userAgent)) {
    return "ontouchstart" in window ? "iOS" : "macOS";
  }

  if (window.navigator.platform === "MacIntel") {
    return "macOS";
  }

  return "No Apple Device";
}

function detectIosDevices() {
  // devices prior to iOS 13
  if (/iPad|iPhone|iPod/.test(navigator.platform)) {
    return navigator.platform;
  }

  // or with document.createEvent('TouchEvent'), which is only available on iPads (and iPhones)
  return !!(
    navigator.platform === "MacIntel" &&
    typeof navigator.standalone !== "undefined"
  )
    ? "iPad"
    : navigator.platform === "MacIntel"
    ? "Macbook"
    : "No Apple Device";
}

function detectDevice() {
  var agent = window.navigator.userAgent;

  // iPhone
  IsIPhone = agent.match(/iPhone/i) != null;

  // iPad up to IOS12
  IsIPad = agent.match(/iPad/i) != null;

  if (IsIPad) {
    IsIPhone = false;
  }

  // iPad from IOS13
  var macApp = agent.match(/Macintosh/i) != null;

  if (macApp) {
    // need to distinguish between Macbook and iPad
    var canvas = document.createElement("canvas");
    if (canvas != null) {
      var context =
        canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
      if (context) {
        var info = context.getExtension("WEBGL_debug_renderer_info");
        if (info) {
          var renderer = context.getParameter(info.UNMASKED_RENDERER_WEBGL);
          if (renderer.indexOf("Apple") != -1) {
            IsIPad = true;
          }
        }
      }
    }
  }

  if (IsIPhone) {
    return "iPhone";
  } else if (IsIPad) {
    return "iPad";
  } else {
    // right now we do not distinguish between the two of them
    return "Desktop computer";
  }
}

/**
 * Detects if current Browser is Chrome. Also works on iOS devices.
 */
function detectChrome() {
  // http://browserhacks.com/
  // https://stackoverflow.com/a/9851769/1238150
  const isChrome =
    !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

  return /Chrome|CriOS/i.test(navigator.userAgent) || isChrome;
}

function detectFirefox() {
  return /Firefox|FxiOS/i.test(navigator.userAgent);
}

function detectBrowser() {
  if (detectChrome()) {
    return "Chrome";
  }
  if (detectFirefox()) {
    return "Firefox";
  }

  // Attention: catchall-fallback with no guarantee
  return "Safari";
}

// DOMContentLoaded
document.addEventListener("DOMContentLoaded", function () {
  // navigator
  document.getElementById("useragent").innerText = navigator.userAgent || "-";
  document.getElementById("platform").innerText = navigator.platform || "-";
  document.getElementById("appVersion").innerText = navigator.appVersion || "-";
  document.getElementById("vendor").innerText = navigator.vendor || "-";

  // feature detection
  document.getElementById("AppleOS").innerText = detectAppleOs();
  document.getElementById("AppleDevice").innerText = detectIosDevices();
  document.getElementById("DeviceDetection").innerText = detectDevice();
  document.getElementById("Browser").innerText = detectBrowser();
  document.getElementById("iOSVersion").innerText = detectIosVersion();
});

站长提示:
1. 平台上所有素材资源,需注册登录会员方能正常下载。
2. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励20K币
3. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
4. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery支持下载Youtube视频缩略图插件

一款Youtube缩略图下载应用插件,可以从Youtube视频中获得高分辨率和低分辨率的缩略图图片。
  实用工具
 195  

jquery拖动DIV区块判断是否跟其它区块重叠触发事件插件

一款拖拽重叠交错触发插件,当一个可移动的DIV区块拖放到另一个DIV区块上时,触发的多种不同的事件。含:重叠次数统计、拖拽物体是否已全部重叠、拖放后回到原位
  实用工具
 198  

jquery轻量级可拖动自定义标记的图片注释工具

DragDropAnnotate是一个轻量级的图片注释工具,可通过拖放拖拽向图片中添加自定义标记、注释和标注热点。
  实用工具
 251  

jquery在线对base64数据进行编码和解码插件

base64.js是一个编码解码器插件,可在线对base64数据进行编码和解码。
  实用工具
 160  

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论