功能介绍:如何利用js语法获取用户代理(User-Agent)、浏览器(Browser)、版本(Version)、渲染引擎(Engine)、操作系统(System)、系统平台(Platform)、屏幕尺寸(Screen size)、剩余电量(Battery)、支持字体(Font Family)等基本信息!
具体实现代码如下:
(async function() {
const info = {};
info["User-Agent"] = navigator.userAgent;
const ua = navigator.userAgent;
let browser = "Unknown",
version = "Unknown";
if (ua.includes("Chrome") && !ua.includes("Edg")) {
browser = "Chrome";
const match = ua.match(/Chrome\/([\d.]+)/);
if (match) {
version = match[1];
}
} else if (ua.includes("Firefox")) {
browser = "Firefox";
const match = ua.match(/Firefox\/([\d.]+)/);
if (match) {
version = match[1];
}
} else if (ua.includes("Safari") && !ua.includes("Chrome")) {
browser = "Safari";
const match = ua.match(/Version\/([\d.]+)/);
if (match) {
version = match[1];
}
} else if (ua.includes("Edg")) {
browser = "Edge";
const match = ua.match(/Edg\/([\d.]+)/);
if (match) {
version = match[1];
}
} else if (ua.includes("OPR") || ua.includes("Opera")) {
browser = "Opera";
const match = ua.match(/OPR\/([\d.]+)/);
if (match) {
version = match[1];
}
} else if (ua.includes("Trident") || ua.includes("MSIE")) {
browser = "Internet Explorer";
const match = ua.match(/(?:MSIE |rv:)([\d.]+)/);
if (match) {
version = match[1];
}
}
info["Browser"] = browser;
info["Version"] = version;
let engine = "Unknown";
if (ua.includes("WebKit")) engine = "WebKit";
else if (ua.includes("Gecko")) engine = "Gecko";
else if (ua.includes("Trident")) engine = "Trident";
info["Engine"] = engine;
let os = "Unknown";
if (ua.includes("Windows")) os = "Windows";
else if (ua.includes("Mac OS")) os = "macOS";
else if (ua.includes("Linux")) os = "Linux";
else if (ua.includes("Android")) os = "Android";
else if (ua.includes("iPhone") || ua.includes("iPad")) os = "iOS";
info["System"] = os;
info["Platform"] = navigator.platform;
info["Screen size"] = `${screen.width}x${screen.height}`;
info["Client size"] = `${window.innerWidth}x${window.innerHeight}`;
if (navigator.userAgentData) {
const {
architecture
} = navigator.userAgentData;
info["Architecture"] = architecture
} else {
info["Architecture"] = ''
}
const isMobile = /Mobi|Android|iPhone|iPad/i.test(ua);
info["Device type"] = isMobile ? "Mobile": "Desktop";
info["Device Pixel Ratio"] = window.devicePixelRatio;
info["Device Memory"] = navigator.deviceMemory || "Unknown";
const canvas = document.createElement("canvas");
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
let gpu = "Unknown";
if (gl) {
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
if (debugInfo) {
gpu = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL)
}
}
info["GPU model"] = gpu;
info["Language"] = navigator.language;
info["Timezone"] = Intl.DateTimeFormat().resolvedOptions().timeZone;
info["Is Online"] = navigator.onLine;
if ("getBattery" in navigator) {
const battery = await navigator.getBattery();
info["Battery"] = `${(battery.level * 100).toFixed(0)}%`;
info["Is charging"] = battery.charging;
} else {
info["Battery"] = "Unavailable";
info["Is charging"] = "Unavailable"
}
const isBot = /bot|crawler|spider|slurp|teoma/i.test(ua);
info["Is robot"] = isBot;
const isWebview = /wv|webview/i.test(ua);
info["Is Webview"] = isWebview;
info["Is Touch Screen"] = "ontouchstart" in window;
info["Is Support WebGL"] = !!gl;
info["Font Family"] = getComputedStyle(document.body).fontFamily;
console.log('info', info)
})();
Screenity官网:一款专为Chrome浏览器设计的屏幕录制和标注工具
cookie存储教程:Chrome浏览器保存位置(设置/获取Cookie)
上面是“JS获取当前电脑浏览器基本信息”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_20194.html
workflows工作流
小丑鱼马林在鱼缸里游来游去ComfyUI工作流
一条赤壁龙从蛋中孵化出来ComfyUI工作流
丛林里坐着一尊佛像
一套可爱的动漫生物蓬松贴纸图标
一尊白玉猴王ComfyUI工作流
3D圆形玉雕图案comfyui工作流
一个女孩骑着一辆生锈的现代摩托车
一个质朴的木制窗户上放着各种葫芦、南瓜等
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

js+css3做一个灯泡开灯关灯效果
一起去看流星雨(代码)
纯css制作卡通头像(随鼠标转头)
HTML5 Canvas 刻度尺
Bootstrap可视化拖放布局
css3画弹珠,可以滚动!
用canvas实现画板涂鸦效果
纯CSS饼图效果









