<meta charset="utf-8"> <title>canvas获取浏览器指纹-唯一的设备标识</title> <script> function bin2hex(str) { var result = ""; for (i = 0; i < str.length; i++ ) { result += int16_to_hex(str.charCodeAt(i)); } return result; } function int16_to_hex(i) { var result = i.toString(16); var j = 0; while (j+result.length < 4){ result = "0" + result; j++; } return result; } function cans(str){ var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var txt = 'http://security.tencent.com/'; ctx.textBaseline = "top"; ctx.font = "14px 'Arial'"; ctx.textBaseline = "tencent"; ctx.fillStyle = "#f60"; ctx.fillRect(125,1,62,20); ctx.fillStyle = "#069"; ctx.fillText(txt, 2, 15); ctx.fillStyle = "rgba(102, 204, 0, 0.7)"; ctx.fillText(txt, 4, 17); var b64 = canvas.toDataURL().replace("data:image/png;base64,",""); var bin = atob(b64); var crc = bin2hex(bin.slice(-16,-12)); //var crc = bin.slice(-16,-12); return crc;//alert(crc); } cans() </script> <p>canvas获取浏览器指纹-唯一的设备标识:<span id="cab"></span></p> <br /><br /> <script> document.getElementById("cab").innerHTML=cans("http://security.tencent.com/"); </script>