@hoge1e3/unload
v1.0.0
Published
A utility to handle the beforeunload event, preventing accidental page exits with an optional cancellation callback.
Readme
@hoge1e3/unload
A utility to handle the beforeunload event, preventing accidental page exits with an optional cancellation callback.
Installation
npm install @hoge1e3/unload
Usage
import setUnload from "@hoge1e3/unload";
const unloadHandler = setUnload({
oncancel: () => console.log("Unload prevented!")
});
// To force allow unloading:
unloadHandler.setForce(true);API
- setUnload(options?: { oncancel?: () => void })
options.oncancel(optional): A function to be called when the unload action is canceled.
- Returns an object with:
setForce(force: boolean): Allows forced unloading when true.
License
MIT
