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






…
Hi! Your article rocks and can be a great understand!…
…
I discovered your blog on google and verify a couple of of the early posts. Retain up the great perform. I just added up your RSS feed to my MSN News Reader. Searching forward to reading through a lot more from you later on!…
…
Quite regularly I go to this weblog. It incredibly a great deal is pleasant to me. Thanks the author!…
…
Me and my friend were arguing about an matter similar to this! Now I realize that I had been proper. lol! Thanks with the data you write-up….
…
Hi, thank you so very much for these tips!…
…
I found your blog on google and check a couple of of the early posts. Preserve up the very good operate. I just additional up your RSS feed to my MSN News Reader. Looking forward to reading through far more from you later on!…
…
Primary issue , A big thanks for you to open my eyes….
…
Hi, thank you so a lot for these ideas!…
…
It’s excellent to possess the ability to study a very good quality article with helpful specifics on topics that plenty are fascinated on. The point that the facts indicated are all first hand on live experiences even support additional. Keep on perfo…
…
Sure glad that I navigated on your page by accident. I’ll be subscribing in your feed to ensure I can get the latest updates. Appreciate all the info here…
…
One more new write-up with strong points, I’ve been a lurker the following to get a brief time but desire to become much a lot more engaged from the long term….
…
As usual this was a thoughtful post today. You make me want to maintain coming back again and forwarding it my followers…….
Beneficial brief and this post helped me alot. thank you
…
Hi, where did you get this details can you please assistance this with some proof or you may perhaps say some very good reference as I and other people will actually enjoy. This info is truly good and I will say will always be useful if we try it possi…