Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/preco21/prevent-unload
Prevent page unloading from the user's action
https://github.com/preco21/prevent-unload
beforeunload browser page prevent unload
Last synced: about 1 month ago
JSON representation
Prevent page unloading from the user's action
- Host: GitHub
- URL: https://github.com/preco21/prevent-unload
- Owner: preco21
- License: mit
- Created: 2016-01-11T03:05:59.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-08T12:21:20.000Z (over 4 years ago)
- Last Synced: 2024-11-03T08:04:27.907Z (about 2 months ago)
- Topics: beforeunload, browser, page, prevent, unload
- Language: JavaScript
- Homepage:
- Size: 3.75 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prevent-unload
[![Code Style Prev](https://img.shields.io/badge/code%20style-prev-32c8fc.svg)](https://github.com/preco21/eslint-config-prev)
[![NPM Version](https://img.shields.io/npm/v/prevent-unload.svg)](https://www.npmjs.com/package/prevent-unload)
[![Build Status](https://travis-ci.org/preco21/prevent-unload.svg?branch=master)](https://travis-ci.org/preco21/prevent-unload)
[![Dependency Status](https://dependencyci.com/github/preco21/prevent-unload/badge)](https://dependencyci.com/github/preco21/prevent-unload)> Prevent page unloading from the user's action
## Install
```bash
$ npm install prevent-unload
```## Usage
```javascript
import preventUnload, {cancel} from 'prevent-unload';const handler = preventUnload();
cancel(handler);
```## API
### preventUnload([message])
* `message` String (optional) - Message to display on confirm popup. Default is platform specified.
Apply page unloading prevention. If user attempt to close current web page after calling the method, then browser blocks page unloading and shows up popup with specified message.
This method returns reference of `handler`, which can be used for cancel the behavior.
### preventUnload.cancel(handler)
* `handler` Function - Handler reference to cancel event.
Cancel page unloading prevention.
## License
[MIT](http://preco.mit-license.org/)