[英]How can I delete a Blob in Internet Explorer?
我在用
$.ajax({
url: '/search',
data: $('form').serialize(),
type: 'POST',
async: true,
// process the response from the backend
success: function(response) {
console.log(response);
if (response.search_text !== "") {
$('#search_result_text').html("Your search " + "<font color='red'>" + response.search_text +
"</font>" + " in category " + "<font color='red'>" + response.category + "</font>" +
" has " + "<font color='red'>" + response.amount_hits_search_text + "</font>" + " hits in:")
$('#hits_document').html("all documents: " + "<font color='red'>" +
response.amount_hits_document_total + "</font>" + "<br>" + "mgmt. documents: " +
"<font color='red'>" + response.amount_hits_documents_mgmt + "</font>")
export_csv.style.visibility = "visible";
}
// function to export all hit results
$('#export_csv').click(function() {
console.log("trying to download")
var blob = new Blob([response.csv], {
type: "text/csv;charset=utf-8;"
});
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, response.search_text + " " + response.category + ".csv")
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("target", "_blank")
link.setAttribute("download", "fileName.csv");
link.style = "visibility:hidden";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
link.removeChild()
URL.revokeObjectURL(url)
}
}
})
)}
)}
為 Internet Explorer 創建一個 blob。
“export_csv”按鈕會生成一個 CSV 文件,之后我可以下載它。 但我意識到,blob 沒有被“覆蓋”。 當我創建了 3 個 CSV 文件並每次點擊下載它們時,第四個 CSV 和點擊也將導致下載所有前 3 個 CSV/blob 文件!
下載后如何刪除每個 blob?
先感謝您。
@ChrisG 的大道具。
我可以通過添加 $("#export_csv").off("click"); 來簡單地修復它。 在ajax請求之前。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.