I have a logout button which should logout user from the session. But first I want to confirm the message whether he needs to logout or not. So, I found window.onbeforeunload but the problem is whether I am clicking stay on page or leave the page in both the cases I am not able to restrict the code to not logging out of the session. How do I check whether what user has choosen so on the basis of that I will expire the session or leave as it is.
I know it could be easy but I am not able to get the condition to check.
<input type='button' name='button_logout' value='Logout' onClick='logoutUser()'>