createObjectURL在ie10中不起作用 [英] createObjectURL does not work in ie10

查看:313
本文介绍了createObjectURL在ie10中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从indexedDB读取base64编码的文件,并尝试将其作为blob url链接到它。下面的代码在Chrome中工作正常但是当我点击ie10中的链接时没有任何反应。我可以在链接的属性上看到href是blob:66A3E18D-BAD6-44A4-A35A-75B3469E392B看起来是正确的。有人看到我做错了吗?

I am reading a base64 encoded file from indexedDB and trying to link to it as a blob url. The code below works fine in Chrome but when I click the link in ie10 nothing happens. I can see on the properties of the link that the href is blob:66A3E18D-BAD6-44A4-A35A-75B3469E392B which seems right. Anyone see what I'm doing wrong?

下载附件

           //convert the base64 encoded attachment string back into a binary array
            var binary = atob(attachment.data);
            var array = [];
            for(var i = 0; i < binary.length; i++) {
                array.push(binary.charCodeAt(i));
            }

            //create a blob from the binary array
            var myBlob=new Blob([new Uint8Array(array)], {type: attachment.content_type});

            //create a url hooked to the blob
            downloadURL = (window.webkitURL ? webkitURL : URL).createObjectURL(myBlob);

            //set the attachment link to the url
            $('#attachmentLink').attr("href", downloadURL);
            $("#attachmentLink").text(fileName);


推荐答案

想出来。 IE10不想在新窗口中打开blob网址,正如我上面的代码所做的那样。当我将blob url设置为img标签的src来显示我的文件时,我才能完成这项工作,幸运的是它仍然是一个图像。

Figured it out. IE10 does not want to open a blob url in a new window, as my code above is trying to do. I could only make this work when I set the blob url as the src of an img tag to display my file, which luckily is an image anyway.

这篇关于createObjectURL在ie10中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆