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 click methods 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!
See the full demo posted in our creations area.
Download Plugin
Version 1.0 - onUserExit js files + dependencies
Download the complete demo here.
The full project can also be found on the jQuery website in the plugins directory under onUserExit.
Please feel free to submit suggestions for changes to this plugin!





web analytics 2.0









