图片数据流实现
由于有些东西不希望通过直接预览或者盗用,例如图片不想被别人直接获取到
1、图片显示html
<img src="" class="pull-right i18n-input" id="captcha" style="cursor: pointer;"
onclick="javascript:getIdentityCode();" title="点击刷新" alt="captcha" selectname="refresh" selectattr="title" >
2、js处理(使用js生成对象)
function getIdentityCode(){ var xmlhttp; xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","需要访问的url",true); xmlhttp.responseType = "blob"; xmlhttp.onload = function(){ console.log(this); if (this.status == 200) { var blob = this.response; var img = document.getElementById("captcha"); img.onload = function(e) { window.URL.revokeObjectURL(img.src); }; img.src = window.URL.createObjectURL(blob); } } xmlhttp.send(); }
浙公网安备 33010602011771号