1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #12241 from escapewindow/prevent-default

confirm if leaving a modified form without saving
This commit is contained in:
Brendan Dahl 2020-08-20 17:56:59 -07:00 committed by GitHub
commit 10f61b8c96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 6 deletions

View file

@ -127,6 +127,12 @@ 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}
@ -436,6 +442,12 @@ 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", {