我正在使用AngularJS和PASSPORT編寫應用程序進行身份驗證。我想擁有登錄後的功能,當瀏覽器窗口關閉時,用戶會自動註銷。AngularJS在關閉瀏覽器窗口時自動註銷
這是我的註銷功能在我廠:
app.factory('authenticate', ['$http', '$window', function($http, $window){
authenticate.logOut = function(){
$window.localStorage.removeItem('token');
};
,我想這在HTML的底部添加一個腳本:
window.onbeforeunload = logOut();
但是,這是行不通的。我應該做什麼不同?當使用
window.onbeforeunload = function(authenticate)
{
authenticate.logOut();
return false;
};
在進行作業時刪除包袱 – dandavis
爲什麼不使用sessionStorage而不是localStorage? 「sessionStorage」完全符合你所需要的行爲 - 當瀏覽器關閉時,所有的東西都會被刪除。 –
刪除parens沒有工作@dandavis – OneMoreQuestion