Add beforeunload interceptor if archive is loaded

Fixes #645
This commit is contained in:
Jaifroid 2024-10-26 14:53:53 +01:00
parent 05b1ee6305
commit 3154de3e3c

View File

@ -32,6 +32,18 @@ window.onerror = function (msg, url, line, col, error) {
return true; return true;
}; };
// Set a beforeUnload handler to prevent app reloads without confirmation if a ZIM file is loaded
window.addEventListener('beforeunload', function (event) {
if (appstate && appstate.selectedArchive && params.appCache) {
var confirmationMessage = 'Warning: you may have to reload the ZIM archive if you leave this page!';
event.preventDefault();
// Included for legacy support, e.g. Chrome/Edge < 119
event.returnValue = confirmationMessage;
// For modern browsers
return confirmationMessage;
}
});
/** /**
* Provides caching for assets contained in ZIM (variable needs to be available app-wide) * Provides caching for assets contained in ZIM (variable needs to be available app-wide)
* It significantly speeds up subsequent page display. See kiwix-js issue #335 * It significantly speeds up subsequent page display. See kiwix-js issue #335