javascript 破解其他网站的防盗链图片

Javascript源码:

function showImg( url ) {
        var frameid = 'frameimg' + Math.random();
        window.img = '<img id="img" src=''+url+'?'+Math.random()+'' /><script>window.onload = function() { parent.document.getElementById(''+frameid+'').height = document.getElementById('img').height+'px'; }<'+'/script>';
        document.write('<iframe id="'+frameid+'" src="javascript:parent.img;" frameBorder="0" scrolling="no" width="100%"></iframe>');

调用方法:

showImg('图片地址');

兼容性:
已测试IE6、IE7、IE8、chrome 7、FF3.6、Opera10.63

防御方法:
1、不允许referer为空(不建议,因在某些开启隐私模式的浏览器中,或https页面引用下,referer是空的);
2、地址变更(lighttpd的是根据有效时间,nginx的根据是md5);
3、登录校验(如必须登录网站帐号后才能访问)