diff --git a/api/js/etemplate/etemplate2.js b/api/js/etemplate/etemplate2.js index b54b4d6001..a394dcdc36 100644 --- a/api/js/etemplate/etemplate2.js +++ b/api/js/etemplate/etemplate2.js @@ -324,14 +324,17 @@ var etemplate2 = /** @class */ (function () { /** * Download a URL not triggering our unload handler and therefore destroying our et2 request * + * We use a new anchor element to avoid not destroying other etemplates as well, which + * is what happens if we use window.location + * * @param {string} _url */ etemplate2.prototype.download = function (_url) { - // need to unbind unload handler to NOT destroy et2 session - this.unbind_unload(); - document.location = _url; - // bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!) - window.setTimeout(jQuery.proxy(this.bind_unload, this), 100); + var a = document.createElement('a'); + a.href = _url; + a.download = 'download'; + // Programmatically trigger a click on the anchor element + a.click(); }; /** * Loads the template from the given URL and sets the data object diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index 6f0dfed182..ff97cd38f1 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -414,17 +414,19 @@ export class etemplate2 /** * Download a URL not triggering our unload handler and therefore destroying our et2 request * + * We use a new anchor element to avoid not destroying other etemplates as well, which + * is what happens if we use window.location + * * @param {string} _url */ download(_url) { - // need to unbind unload handler to NOT destroy et2 session - this.unbind_unload(); + const a = document.createElement('a'); + a.href = _url; + a.download = 'download'; - document.location = _url; - - // bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!) - window.setTimeout(jQuery.proxy(this.bind_unload, this), 100); + // Programmatically trigger a click on the anchor element + a.click(); } /**