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

confirm if leaving a modified form without saving

This commit is contained in:
Aki Sasaki 2020-08-18 13:50:23 -07:00
parent 965d20db2a
commit 83365a3756
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", {