
Security News
Oxlint Introduces Type-Aware Linting Preview
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
before-unload
Advanced tools
A generic onbeforeunload handler. Will check a list of supplied conditions to determine if it is safe to unload.
A generic onbeforeunload handler. Will check a condition, or a list of supplied conditions, to determine if it is safe to unload.
The examples are available on the github project page.
It supports newer ES5 compatible browsers. And it should be able to support most elderly browsers if you provide them with an ES5 shim.
Install it from npm:
$ npm install before-unload
In the following example, the user will be prompted on the beforeunload event, if the ViewModel.hasChanges method returns a truthy value.
new BeforeUnload('Are you sure you want to leave?', function () {
return ViewModel.hasChanges();
});
In the following example, the user will be prompted on the beforeunload event, if the ViewModel.hasChanges method or the Storage.unsavedChanges method returns a truthy value.
new BeforeUnload('Are you sure you want to leave?', [
function () {
return ViewModel.hasChanges();
},
function () {
return Storage.unsavedChanges();
}
]);
In the following example, a different warning is shown for one of the conditions.
new BeforeUnload('Are you sure you want to leave?', [
function () {
return ViewModel.hasChanges();
},
function () {
return Storage.unsavedChanges();
},
function () {
return SomeObject.isItOkayToLeave() ? false : 'A custom error message';
}
]);
If you store a reference to the BeforeUnload object, you can unregister the event listener.
If a user attempts to leave the page after the unregister call, she will not be prompted.
var beforeUnload = new BeforeUnload(
'Are you sure you want to leave?',
function () {}
);
beforeUnload.unregister();
FAQs
A generic onbeforeunload handler. Will check a list of supplied conditions to determine if it is safe to unload.
We found that before-unload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.