2013-01-07 42 views
0

我正在從indexedDB讀取一個base64編碼文件,並試圖鏈接到它作爲blob url。下面的代碼在Chrome中正常工作,但是當我點擊IE10中的鏈接時,什麼也沒有發生。我可以看到鏈接的屬性,href是blob:66A3E18D-BAD6-44A4-A35A-75B3469E392B看起來沒錯。任何人看到我做錯了什麼?createObjectURL在ie10中不起作用

下載附件

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

您是否諮詢過IE的開發人員工具以查看是否遇到錯誤? – Madbreaks

回答

0

想通了。 IE10不想在新窗口中打開blob url,因爲我上面的代碼試圖去做。當我將blob url設置爲img標籤的src來顯示我的文件時,我只能做這個工作,無論如何這幸運地是一個圖像。

+0

它是否適用於IE 11中1024字節以上的文件? – Sreekumar

+0

這僅適用於某些文件images/css,文件大小對於不同於數據url的對象網址無關緊要。 – bhantol