Smart jQuery Plugin For Page Leave Event - pageleave

File Size: Unknown
Views Total: 8994
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Smart jQuery Plugin For Page Leave Event - pageleave

pageleave is a smart jQuery plugin that triggers an event when your visitors want to leave the current page. Unlike the other jQuery plugins which catch the page leave event, pageleave plugin will fire a custom event when your visitors move the mouse to the location bar. This could be used to show a confirm dialog, a modal window , or something else.

See also:

Basic Usage:

1. Include jQuery javascript library and jQuery pageleave plugin on the web page

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="jquery.pageleave.js"></script>

2. The javascript

<script>
$(document).on('pageleave', function() {
alert("Please don't leave me!");
        // do sth. else
});
$.fn.pageleave();
</script>

3. The options

$.fn.pageleave({
container: document, // This is the container the plugin should be attached to. Defaults to document
limitX: screen.width, // The plugin will fire when three conditions are fulfilled, one of them being an x-position below limitX (the others being limitY and timeTillActive).
limitY: 15, // The plugin will fire when three conditions are fulfilled, one of them being a y-position below limitY (the others being limitX and timeTillActive).
timeTillActive: 5000, // This is the time the plugin waits until it's active, so that it doesn't fire when a user accidentally traverses the area specified by limitX and limitY in the beginning.
times: 3, // When you specifiy a positive number, this is how many times the plugin fires when all conditions are fulfilled. -1 means always.
callback: null // When callback is a function it will be called instead of the default behaviour (triggering the "pageleave" event). "times" still applies.
};
);

This awesome jQuery plugin is developed by jquerypageleave. For more Advanced Usages, please check the demo page or visit the official website.