2016-10-22 72 views

回答

0

您可以使用onunloadonbeforeunload事件來處理這一點,但與條件,他們將解僱即使導航到其他網站上點擊鏈接

angular 
    .module('app', []) 
    .controller('AppController', function ($localStorage, $window) { 
    $window.onunload = function() { 
     $localStorage.setItem('LastLoggedOutTime', new Date()); 
    } 
    }); 
+0

上面的代碼將會給onload事件的時間,但我想關閉時間,當我關閉選項卡或browser.Please建議? –

0
angular.module('app', []) 
    .controller('exitController', function($scope, $window) { 
     $scope.onExit = function() { 
      // your function 
     }; 

     $window.onbeforeunload = $scope.onExit; 
}); 
1

可以使用... beforeunload

$(document).ready(function() 
{ 
    $(window).bind("beforeunload", function() { 
     return "Do you really want to close?"; 
    }); 
}); 

With pure JS

window.addEventListener("beforeunload", function (e) { 

}); 

https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Fbeforeunload

+0

是的,你的代碼是提醒我leav瀏覽器或留在瀏覽器中關閉標籤或瀏覽器的工作,但 –

+0

你的代碼提醒我關閉或停留在瀏覽器,但我如何存儲關閉時間關閉瀏覽器||請提出建議? –

+0

您可以使用$ locationChangeStart或$ stateChangeSuccess與beforeunload事件...查看此指令... http://stackoverflow.com/a/22866537/337128 – Thalaivar