From 24ec89c2206837e78aa1e7399b0690007da0a4d6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 6 Nov 2018 09:46:17 -0500 Subject: [PATCH] open PDF in new window using built-in browser viewer --- src/services/webPlatformUtils.service.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index 4d5bd1b7e2..55f316e6d1 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -109,8 +109,10 @@ export class WebPlatformUtilsService implements PlatformUtilsService { let blob: Blob = null; let type: string = null; const fileNameLower = fileName.toLowerCase(); + let doDownload = true; if (fileNameLower.endsWith('.pdf')) { type = 'application/pdf'; + doDownload = false; } else if (fileNameLower.endsWith('.xlsx')) { type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; } else if (fileNameLower.endsWith('.docx')) { @@ -141,10 +143,13 @@ export class WebPlatformUtilsService implements PlatformUtilsService { navigator.msSaveBlob(blob, fileName); } else { const a = win.document.createElement('a'); + if (doDownload) { + a.download = fileName; + } else { + a.target = '_blank'; + } a.href = win.URL.createObjectURL(blob); - a.download = fileName; a.style.position = 'fixed'; - a.target = '_blank'; win.document.body.appendChild(a); a.click(); win.document.body.removeChild(a);