Angular deleting cookies on exiting website
1 answer
Try the following:
function clearCookies(){
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++){
var vals = cookies[i].split("=");
document.cookie = vals[0] + "=;expires=Thu, 21 Sep 1979 00:00:01 UTC;";
}
}
// you will need jquery for this
$(window).on('beforeunload', function () {
clearCookies()
});
or the clear function in angular way:
function clearCookies(){
angular.forEach($cookies, function (value, key) {
$cookieStore.remove(key);
});
}
But if you can use session cookies (without expiration), they are automatically deleted by the browser when the user closes the browser.
0
source to share