获取浏览器设备信息

function browser() {
var e = document.createElement("canvas");
if (e && "function" == typeof e.getContext)
for (var t = ["webgl", "webgl2", "experimental-webgl2", "experimental-webgl"], r = 0; r < t.length; r++) {
var i = t[r],
o = e.getContext(i);
if (o) {
var a = {};
a.context = i,
【获取浏览器设备信息】a.version = o.getParameter(o.VERSION),
a.vendor = o.getParameter(o.VENDOR),
a.sl_version = o.getParameter(o.SHADING_LANGUAGE_VERSION),
a.max_texture_size = o.getParameter(o.MAX_TEXTURE_SIZE);
var c = o.getExtension("WEBGL_debug_renderer_info");
return c && (a.vendor = o.getParameter(c.UNMASKED_VENDOR_WEBGL), a.renderer = o.getParameter(c.UNMASKED_RENDERER_WEBGL)), a
}
}
return {}
}
var swidth = window.screen.width || ""; //屏幕分辨率的宽度
var sheight = window.screen.height || ""; //屏幕分辨率的高度
var sp = window.devicePixelRatio || ""; //设备像素比
var version = browsers.version || getVersion(); //浏览器version
var renderer = browsers.renderer || getRenderer(); //浏览器renderer
function getRenderer() {
var canvas = document.createElement('canvas');
gl = canvas.getContext('webgl') || canvas.getContext('webgl2') || canvas.getContext('experimental-webgl2') || canvas.getContext('experimental-webgl');
if (gl === null) {
return '';
}
debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
if (debugInfo === null) {
return '';
} else {
return gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
}
}
function getVersion() {
var canvas = document.createElement('canvas');
gl = canvas.getContext('webgl') || canvas.getContext('webgl2') || canvas.getContext('experimental-webgl2') || canvas.getContext('experimental-webgl');
if (gl == null) {
return '';
}
debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
return gl.getParameter(gl.VERSION);
}

    推荐阅读