mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 15:18:11 +00:00
25 lines
620 B
TypeScript
25 lines
620 B
TypeScript
export function openPdfBlob(blob: Blob, filename: string, targetWindow?: Window | null) {
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
if (targetWindow && !targetWindow.closed) {
|
|
targetWindow.location.href = url;
|
|
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
|
return true;
|
|
}
|
|
|
|
const opened = window.open(url, '_blank');
|
|
if (opened) {
|
|
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
|
return true;
|
|
}
|
|
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
a.remove();
|
|
URL.revokeObjectURL(url);
|
|
return false;
|
|
}
|