2017-02-16 757 views
0

我已經實現了下列代碼,它在Safari中下載文件,但文件名變爲'無標題'。在其他瀏覽器中,它運行良好。在Safari中下載文件名時會出現'未命名'

var saveData = (function() { 
var base64 = "data:application/msword;base64,iVBOR---<some data>---JoU8gAAAAASUVORK5CYII="; 
          var uri = encodeURI(base64); 
           var anchor = document.createElement('a'); 
           document.body.appendChild(anchor); 
           anchor.href = uri; 
           anchor.download = "hello"; 


        anchor.click(); 
             document.body.removeChild(anchor); 
}()); 
    saveData(); 

這是鏈接到JSFiddle來得到這個測試。 JSFiddle_here

回答

0

anchor.download = "hello";

確保您使用的Safari版本是10.1或以上的下載屬性在此link

編輯支持Safari瀏覽器從10.1只顯示:

您可以使用FileSaver.js它支持很多瀏覽器。

+1

他說,它的工作,但只有文件名是「無標題」。 Iam確信他知道在safari中支持屬性「下載」。 – lin

+0

是的,下載的內容工作正常,但文件名是'未知'。我也使用過FileSaver。我在Safari中工作不好。 – Apoorv