diff --git a/src/core/js/ext_bookmarks.js b/src/core/js/ext_bookmarks.js index 178280d9c21d90775065752af95a9e4a75d2e407..d99ff362d8a26ee4818a76a624c80f55f757c419 100644 --- a/src/core/js/ext_bookmarks.js +++ b/src/core/js/ext_bookmarks.js @@ -243,6 +243,23 @@ var ext_bookmarks = function ($, logger, config) { return `${preamble}${header}${rows.join(newline)}`; } + /** + * Download the table with a given filename. + * + * This method adds a temporay <A> element to the dom tree and triggers + * "click" because otherwise the filename cannot be set. + * + * See also: + * https://stackoverflow.com/questions/21177078/javascript-download-csv-as-file + */ + const download = function (table, filename) { + console.log("download"); + const link = $(`<a style="display: none" download="${filename}" href="${table}"/>`); + $("body").append(link); + link[0].click(); + link.remove(); + } + /** * Trigger the download of the TSV table with all current bookmarks. * @@ -261,7 +278,7 @@ var ext_bookmarks = function ($, logger, config) { const uri = get_collection_link(ids); const leading_comments = [encodeURIComponent(`#Link to all entities: ${uri}`)]; const export_table = await get_export_table(ids, undefined, undefined, undefined, leading_comments); - window.location.href = export_table; + download(export_table, "bookmarked_entities.tsv"); } /**