Last active
December 28, 2015 04:59
-
-
Save hgoebl/7446989 to your computer and use it in GitHub Desktop.
Example code for window.onbeforeunload (not generally usable!) There are two event-handlers for loggedOut and loggedIn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.logout is just a AJAX call doing logout | |
var App = { | |
// ... | |
logout: function () { | |
return $.ajax({ | |
url: REST.postLogout, | |
type: 'POST' | |
}); | |
} | |
} | |
App.when = { | |
loggedOut: function () { | |
$('html').removeClass('logged-in').addClass('logged-out'); | |
window.onbeforeunload = null; | |
}, | |
loggedIn: function () { | |
$('html').removeClass('logged-out').addClass('logged-in'); | |
window.onbeforeunload = function () { | |
App.logout(); | |
// return nothing, otherwise a confirm dialog of the browser appears | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment