I have to store closingtime after closing of tab and browser.that closing time should be stored in localstorage in angularjs.
I am using $localStorage and $window directive.
I have to store closingtime after closing of tab and browser.that closing time should be stored in localstorage in angularjs.
I am using $localStorage and $window directive.
You can use... beforeunload
$(document).ready(function()
{
$(window).bind("beforeunload", function() {
return "Do you really want to close?";
});
});
With pure JS
window.addEventListener("beforeunload", function (e) {
});
You can use onunload and onbeforeunload events to handle this but with the condition that they will fire even while navigating to other sites on clicking links
angular
.module('app', [])
.controller('AppController', function ($localStorage, $window) {
$window.onunload = function () {
$localStorage.setItem('LastLoggedOutTime', new Date());
}
});
angular.module('app', [])
.controller('exitController', function($scope, $window) {
$scope.onExit = function() {
// your function
};
$window.onbeforeunload = $scope.onExit;
});