Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
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.
The npm package before-unload receives a total of 867 weekly downloads. As such, before-unload popularity was classified as not popular.
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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.