
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
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 4,785 weekly downloads. As such, before-unload popularity was classified as 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.