All Projects → willianjusten → on-leave-intent

willianjusten / on-leave-intent

Licence: other
A script to detect if the user is leaving the page and calls a function.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to on-leave-intent

Tracker
Laravel Stats Tracker
Stars: ✭ 2,638 (+6842.11%)
Mutual labels:  user-tracker
cerbero
Track your users interactions
Stars: ✭ 56 (+47.37%)
Mutual labels:  user-tracker

On Leave Content

User moving to close the page and it shows an alert modal

A script to detect if the user is leaving the page after some time and calls a function.

I know most of us don't like those modals that appears when we are leaving the page, but sometimes we need it. And this library is not only for that, you can call any function when the user leaves the page, so use your imagination.

Installing

Install the library via npm install on-leave-intent or yarn add on-leave-intent. Or you can even download the file here and load with the good and old way <script src="on-leave-intent.min.js"></script>.

How to use

If you used npm/yarn, just import the file:

import OnLeaveIntent from 'on-leave-intent';

And now you can use it like:

function callback() {
  console.log('A function to be called when user leaves the page');
}

const delay = 1000; // time in milliseconds defined to start tracking the user

const onLeaveIntent = new OnLeaveIntent(callback, delay);

Testing

You can see the tests on index.test.js, use yarn test to run the tests. If you want to see an example working on the Browser, just run yarn start.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].