The plugins site is currently in development.
We've been looking to provide a higher-quality, spam-free experience at the plugins site for some time, and a major error on our part forced us to shut down the current site before we could put the new one in place. We are developing a new site, and you can follow along with its development on GitHub. For more information about this transition, including steps you can take as a plugin author to prepare, please read our post about what's going on.
onUserExit - Execute Code When a User Leaves Your Website
onUserExit is a jQuery plugin allows you to easily wire a function to execute when the user leaves your website. Internal website pages are filtered out, allowing the function to ONLY trigger when the window is closed or the user navigates to an external website.
I’m sure many of you have read about the javascript function onbeforeunload() or in jQuery $(window).unload() which triggers when a user leaves a page. Well the trouble is if the user clicks on the navigation within your website to go to a separate page from where you are currently (i.e. the user lands on the Home and then navigates to About), this triggers the event, which in this case you don’t want.
The way this is achieved is that upon the page completing load, I actually add onClick events to all internal links within the page that execute a function called “userMovingWithinSite()”, which sets a boolean variable called “movingWithinSite” to true. So now, when the user clicks a navigation link or any link on the website WITHIN the website and the onbeforeunload event triggers, I can check to see if the user is actually leaving the site, or just navigating within it. If they are indeed leaving, then we execute your function!
Updated version 1.1:
Added support for detection of page refresh through F5 key and ctrl+r.
Added support for forms as well, so submissions don't trigger exit event.
