jQuery unload event only for close window not for Link navigation
I am using this code for logging out user when closes the page, but the user will logout also when clicking on other links (same website): $( window ).unload(function() { $.ajax({url:"?logout&leave=yes", async:false}) }); Is there any way to distinguish between link navigation and real page close? EDIT: I am currently implemented this solution, but it lacks to detect page reload $('a').click(function(){ var url = $(this).attr("href"); window.onbeforeunload = null; $(window).unbind('beforeunload'); window.location = url; }); Try the following solutions, hope this helps <script> $(window).bind(