FruitBankHybridApp/FruitBankHybrid.Shared/wwwroot/js/fileDownload.js

20 lines
759 B
JavaScript

// Triggers a client-side file download from in-memory text (no server round-trip).
// Used e.g. by the EKÁER grid to save the generated trade-card XML as a file.
window.downloadFileFromText = function (filename, content, mime) {
try {
const blob = new Blob([content], { type: mime || 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename || 'download';
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 0);
} catch (e) {
console.error('downloadFileFromText failed', e);
}
};