码迷,mamicode.com
首页 > 其他好文 > 详细

将地址转成blob格式(服务器下运行)

时间:2017-05-08 14:21:43      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:地址   img   url   cti   status   win   doc   服务   xhr   

<div id="forAppend" class="demo"></div>
<script>
    var eleAppend = document.getElementById("forAppend");
    window.URL = window.URL || window.webkitURL;
    if (typeof history.pushState == "function") {
        var xhr = new XMLHttpRequest();
        xhr.open("get", "test/images/1.gif", true); xhr.responseType = "blob"; xhr.onload = function() { 

if (this.status == 200) { var blob = this.response; var img = document.createElement("img"); img.onload = function(e) {
window.URL.revokeObjectURL(img.src);
// 清除释放 }; img.src = window.URL.createObjectURL(blob); eleAppend.appendChild(img); } }
xhr.send();
}

else {
eleAppend.innerHTML
= <p style="color:#cd0000;">浏览器不给力,请更换浏览器后重试</p>;
}

</script>

 

将地址转成blob格式(服务器下运行)

标签:地址   img   url   cti   status   win   doc   服务   xhr   

原文地址:http://www.cnblogs.com/heyiming/p/6824376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!