From 82a5bfe198caa0805ff2127f20437ae5ba6d8437 Mon Sep 17 00:00:00 2001 From: HarveyKandola Date: Sun, 29 Jul 2018 16:41:18 -0400 Subject: [PATCH] Better client-side download file process --- gui/app/services/browser.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gui/app/services/browser.js b/gui/app/services/browser.js index c9a04c7c..0c483ecd 100644 --- a/gui/app/services/browser.js +++ b/gui/app/services/browser.js @@ -55,17 +55,19 @@ export default Service.extend({ }, downloadFile(content, filename) { - let b = new Blob([content], { - type: 'text/html' - }); + let b = new Blob([content], { type: 'text/html' }); - const data = window.URL.createObjectURL(b); - var link = document.createElement('a'); - link.href = data; - link.download = filename; - link.click(); + let a = document.createElement("a"); + a.style = "display: none"; + document.body.appendChild(a); - // For Firefox it is necessary to delay revoking the ObjectURL - setTimeout(function() { window.URL.revokeObjectURL(data), 100}); + let url = window.URL.createObjectURL(b); + + a.href = url; + a.download = filename; + a.click(); + + window.URL.revokeObjectURL(url); + document.body.removeChild(a); } });