生成设备唯一UUID

function generateDeviceID() {
  const navigatorInfo = window.navigator;
  const screenInfo = window.screen;
  const uid = navigatorInfo.mimeTypes.length;
  const ab = navigatorInfo.userAgent.replace(/\D+/g, "");
  const version = navigatorInfo.appVersion.replace(/\D+/g, "");
  const versionNum = screenInfo.height || "";
  const screenSize = screenInfo.width + screenInfo.height;
  return uid + ab + version + versionNum + screenSize;
}
const uniqueId = localStorage.getItem("uuid");
if (!uniqueId) {
  const deviceID = generateDeviceID();
  localStorage.setItem("uuid", deviceID);
}

  

posted @ 2024-10-23 15:58  蜗牛snail  阅读(9)  评论(0)    收藏  举报
蜗牛前端 蜗牛文学