浏览文章
文章信息
前端获取Canvas指纹
13636
代码:
<canvas id="fingerprint"></canvas> <script> window.onload = function() { function hex2bin(hex) { let bytes = [], str; for(let i=0; i< hex.length-1; i+=2) bytes.push(parseInt(hex.substr(i, 2), 16)); return String.fromCharCode.apply(String, bytes); } function getUUID() { let canvas = document.getElementById("fingerprint"); let ctx = canvas.getContext("2d"); ctx.fillStyle = "#FF0000"; ctx.fillRect(0,0,8,10) let b64 = canvas.toDataURL().replace("data:image/png;base64,",""); let bin = window.atob(b64); return hex2bin(bin.slice(-16,-12)); } window.uuid = getUUID(); } </script>