我在这里阅读了很多关于如何拦截窗口关闭和弹出对话框的示例。我需要一些不同的东西。在我的页面关闭或更改之前,我需要调用和完成一个函数。
我在下面更新了我的代码,以帮助更好地解释我的问题。
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;
});
});
});