diff --git a/web/app.js b/web/app.js index 6b06e6aed76c4..949d1c4ad7671 100644 --- a/web/app.js +++ b/web/app.js @@ -1165,6 +1165,14 @@ const PDFViewerApplication = { this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl); this.pdfDocumentProperties.setDocument(pdfDocument, this.url); + const annotationStorage = pdfDocument.annotationStorage; + annotationStorage.onSetModified = function () { + window.addEventListener("beforeunload", beforeUnload); + }; + annotationStorage.onResetModified = function () { + window.removeEventListener("beforeunload", beforeUnload); + }; + const pdfViewer = this.pdfViewer; pdfViewer.setDocument(pdfDocument); const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer; @@ -2951,6 +2959,12 @@ function webViewerKeyDown(evt) { } } +function beforeUnload(evt) { + evt.preventDefault(); + evt.returnValue = ""; + return false; +} + /** * Converts API PageLayout values to the format used by `PDFViewer`. * NOTE: This is supported to the extent that the viewer implements the diff --git a/web/base_viewer.js b/web/base_viewer.js index 385a2ffe0d230..e4dce389ce784 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -127,12 +127,6 @@ function isSameScale(oldScale, newScale) { return false; } -function beforeUnload(evt) { - evt.preventDefault(); - evt.returnValue = ""; - return false; -} - /** * Simple viewer control to display PDF content/pages. * @implements {IRenderableView} @@ -442,12 +436,6 @@ class BaseViewer { const firstPagePromise = pdfDocument.getPage(1); const annotationStorage = pdfDocument.annotationStorage; - annotationStorage.onSetModified = function () { - window.addEventListener("beforeunload", beforeUnload); - }; - annotationStorage.onResetModified = function () { - window.removeEventListener("beforeunload", beforeUnload); - }; this._pagesCapability.promise.then(() => { this.eventBus.dispatch("pagesloaded", {