Skip to content

A small plugin for users wanting to leave your page (based on jquery)

Notifications You must be signed in to change notification settings

Bilal-Abdeen/jquery-pageleave

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jQuery pageleave

A small plugin for users wanting to leave your page (based on jQuery).

Basic idea

While jquery/javascript already have events for users leaving your page (unload, beforeunload), they all have theirs pros and cons. The basic idea behind this small plugin is that a user wanting to leave your page will sooner or later type sth. (probably a url) in the location bar which usually resides on top of the content. This is where this plugin fires and where you could show a modal box asking for feedback, informing them that some content hasn't been saved properly and that you are sick at heart they are leaving...

What it does

Firing an event (after some initial delay) when the user move the mouse to the location bar. This could be used to show a modal box or sth. else.

What it does not

The plugin does not prevent the user from leaving, so please do not rely on it when you have unsaved changes to your database, to the profile or to some docs they have been working on! Additionally, some users move the mouse extremely fast so that the mousemove-handler might not even be aware of the user having scrolled over a specific area. You should really, really only use it for non-essential tasks!

Demo

See a working demo at www.rexmedicus.com/jquerypageleave.

Installation

  1. Download it.
  2. Load it in your js file
  3. Bind it to an appropriate container:
	$(document).on('pageleave', function() {
      	alert("Oh no! Please don't leave me!");
      	// do sth. else
    });
    $.fn.pageleave();

Configuration

Please see the different configuration options at www.rexmedicus.com/jquerypageleave.

Where to go from here

If you encounter any errors or want to add functionality, please do not hesitate to open a Pull Request

About

A small plugin for users wanting to leave your page (based on jquery)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%