页面增加<iframe>
<iframe id="ifa" style="display:none" />
原来html:
<img src="***.jpg" />
改为:
<img data-type="loadimg" data-src="***.jpg" />
执行如下js,即可取消访问Referer,完成初步的跳过反盗链
<script type='text/javascript'> var imgs=document.getElementsByTagName('img'); var newimgarr=[]; for(var i=0;i<imgs.length;i++){ var g=imgs[i]; if(g.getAttribute('data-type')=='loadimg'){ newimgarr.push(g); } } var i=document.getElementById('ifa'); var w=i.contentWindow; for(var j=0;j<newimgarr.length;j++){ var k=newimgarr[j]; (function(k){ var imgurl=k.getAttribute('data-srcc'); getImg(w.document,imgurl,function(){ k.src=imgurl; }); })(k); } function getImg(doc,src,callback){ var img=doc.createElement('img'); img.src=src; img.onload=callback; } </script>