伴随html5的成熟,通过Canvas fingerprinting技术来标识一个唯一的浏览器,唯一性高达99.8%,用户基本无法屏蔽。
下面代码直接可以使用。
<script type="text/javascript" >
alert("获得的浏览器指纹是:"+getCanvasFp());
//获取Canvas Fingerprinting指纹,帆布指纹识别
function getCanvasFp() {
var result = "";
// Very simple now, need to make it more complex (geo shapes etc)
var canvas = document.createElement('canvas');
canvas.width = 200;
canvas.height = 20;
canvas.style.display = 'inline';
var ctx = canvas.getContext('2d');
// detect browser support of canvas winding
// http://t.cn/R7wzrRy
// http://t.cn/AiFHoZG5
ctx.rect(0, 0, 10, 10);
ctx.rect(2, 2, 6, 6);
result += 'canvas winding:' + ((ctx.isPointInPath(5, 5, 'evenodd') === false) ? 'yes' : 'no');
ctx.textBaseline = 'alphabetic';
ctx.fillStyle = '#f60';
ctx.fillRect(125, 1, 62, 20);
ctx.fillStyle = '#069';
// http://t.cn/AiFHoZGx
ctx.font = '11pt no-real-font-123';
ctx.fillText('Cwm fjordbank glyphs vext quiz, \ud83d\ude03', 2, 15);
ctx.fillStyle = 'rgba(102, 204, 0, 0.2)';
ctx.font = '18pt Arial';
ctx.fillText('Cwm fjordbank glyphs vext quiz, \ud83d\ude03', 4, 45);
// canvas blending
// http://t.cn/AiFHoZGt
// http://t.cn/AiFHoZGM
ctx.globalCompositeOperation = 'multiply';
ctx.fillStyle = 'rgb(255,0,255)';
ctx.beginPath();
ctx.arc(50, 50, 50, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.fillStyle = 'rgb(0,255,255)';
ctx.beginPath();
ctx.arc(100, 50, 50, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.fillStyle = 'rgb(255,255,0)';
ctx.beginPath();
ctx.arc(75, 100, 50, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.fillStyle = 'rgb(255,0,255)';
// canvas winding
// http://t.cn/R7wzrRy
// http://t.cn/AiFHoZGf
ctx.arc(75, 75, 75, 0, Math.PI * 2, true);
ctx.arc(75, 75, 25, 0, Math.PI * 2, true);
ctx.fill('evenodd');
if (canvas.toDataURL) {
result += ';canvas fp:' + canvas.toDataURL();
}
// 计算字符串的hash值
var hash = 0;
if (result.length > 0) {
for (i = 0; i < result.length; i++) {
char = result.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
}
return hash;
}
</script>