1
我可以下載一個變量(可以說由用戶填寫表單)在JS在瀏覽器 (我知道一個文件是不是要走的路,並且服務器要做到這一點對我的要求)
我使用這個代碼:
textToSave = "Hello"
var createObjectURL = (window.URL || window.webkitURL || {}).createObjectURL || function(){};
var blob = null;
var content = textToSave;
var mimeString = "application/octet-stream";
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
if(window.BlobBuilder){
var bb = new BlobBuilder();
bb.append(content);
blob = bb.getBlob(mimeString);
}else{
blob = new Blob([content], {type : mimeString});
}
var url = createObjectURL(blob);
var a = document.createElement("a");
a.href = url
a.download = "file.csv";
a.innerHTML = "download file";
a.click();
,並在Chrome中工作正常,但是當我嘗試在IE-11,然後我得到一個BLOB
你有一個想法如何使它工作瀏覽器是獨立的嗎?
好看的圖書館。在任何情況下,對於IE10,它基本上都會調用'navigator.msSaveOrOpenBlob(blob,name)'。 –