简体   繁体   English

createObjectURL在ie10中不起作用

[英]createObjectURL does not work in ie10

I am reading a base64 encoded file from indexedDB and trying to link to it as a blob url. 我正在从indexedDB读取base64编码的文件,并尝试将其链接为Blob网址。 The code below works fine in Chrome but when I click the link in ie10 nothing happens. 下面的代码在Chrome中工作正常,但是当我单击ie10中的链接时,没有任何反应。 I can see on the properties of the link that the href is blob:66A3E18D-BAD6-44A4-A35A-75B3469E392B which seems right. 我可以在链接的属性上看到href为blob:66A3E18D-BAD6-44A4-A35A-75B3469E392B,这似乎是正确的。 Anyone see what I'm doing wrong? 有人看到我在做什么错吗?

Download Attachment 下载附件

           //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);

Figured it out. 弄清楚了。 IE10 does not want to open a blob url in a new window, as my code above is trying to do. IE10不想在新窗口中打开Blob网址,因为我上面的代码正在尝试这样做。 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. 仅当将blob URL设置为img标签的src来显示我的文件时,我才能使此工作正常,幸运的是,该文件还是图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM