I'm trying to logout each time the user closes it's tab. I've saw all similar questions, but I still haven't found anything that works.
Here's what I've done:
<script type="text/javascript">
$(document).ready(function() {
$(window).bind("beforeunload", function() {
confirm("Do you really want to logout?") && $.ajax({
type: "GET",
url: "/admin/account/logout"
})
})
});
</script>
I've tried without the confirm
, but it still doesn't work. I'm absolutely sure that it can be done, since my bank's website has the same functionality.
EDIT:
Without the confirm
it does fire the logout ajax, but even when I browse trough the pages. Which reminds me, that my bank's website uses something like AngularJS, which is not exactly a true link-browsing system, right? Maybe that's why it works there?