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 ).unlo
There is no way to know where does the user want to go when he leaves your page.
Instead on unbinding manually events on click, you could set a flag, and skip AJAX request in your unload callback when this flag is set. Also, note that $(window).unload() is deprecated and should be replaced with: $(window).on('unload', function() {}).
The only solution I can think about, is to set value in a cookie (or LocalStorage) on page unload and check if this value is set on page load. But that won't work if you want to send an AJAX request only when the users leaves your app.
I am afraid we are in front of an XY problem, though. Can't you set some sort of timeout on server-side, which will properly logout user as soon as he is inactive? Even with the link trick, your current solution won't work if the user is logged in multiple times, if he opens a new window/tab, or if he simply lets the page run in background.