I've read many examples here on how to intercept the window closing and popping up a dialog. I need something different. Before my page is closed or changed I need a function to be called and completed.
I've updated my code below to help better explain my question.
window.addEventListener("beforeunload", function(event) {
//I need the done callback function to fire before the page is changed
//I've placed return null in that call because I think I need to pass something back?
visualize({
auth: {
name: "piper",
password: "password",
}
}, function(v) {
//destroy session
v.logout().done(function() {
console.log("JRS Logout");
return null;
});
});
});