From 9e0bb0963f871530b3dcc4931f101aab7880e4e1 Mon Sep 17 00:00:00 2001 From: lionel Date: Mon, 11 Jan 2021 14:38:37 +0100 Subject: [PATCH] Add link in progress div --- js/script.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/script.js b/js/script.js index 0e100a1..1b48aa6 100644 --- a/js/script.js +++ b/js/script.js @@ -190,7 +190,7 @@ function downloadFile(event) { xhr.addEventListener("loadstart", function(e){ this.progressId = progressId; this.name = title; - $("#transProgress").append('
'); + $("#transProgress").append('
'); }); xhr.addEventListener("progress", function(evt) { if (evt.lengthComputable) { @@ -202,7 +202,7 @@ function downloadFile(event) { var speedMB = speed.toFixed(2) + ' MB/s '; $('#' + this.progressId + ' > .name').text(this.name); - $('#' + this.progressId + ' > progress').prop('value', percentComplete); + $('#' + this.progressId + ' > progress').prop('value', percentComplete); $('#' + this.progressId + ' > .speed').text(speedMB + humanFileSize(fileLoad) + ' / ' + humanFileSize(fileSize)); } }, false); @@ -221,12 +221,16 @@ function downloadFile(event) { success: function(data){ lock = 0; var blob = data; - var a = document.createElement("a"); var blobUrl = window.URL.createObjectURL(new Blob([blob], {type: blob.type})); + console.log(blobUrl); + + $('#' + progressId + ' > .name').attr("href", blobUrl); + $('#' + progressId + ' > .name').attr("download", title); + + var a = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; a.href = blobUrl; - console.log(blobUrl); a.download = title; a.click(); a.remove();