<script>
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var ctx = canvas.getContext('2d');
ctx.fillStyle = "#aaa";
ctx.fillRect(0, 0, 16, 16);
ctx.fillStyle = "#afa";
ctx.fillRect(4, 4, 8, 8);
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = canvas.toDataURL("image/x-icon");
document.getElementsByTagName('head')[0].appendChild(link);
</script>
针对当前过时的 Internet Explorer(<9)版本,需要像Explorer Canvas这样的解决方法。请查看官方说明以了解如何操作。