After conducting extensive research across various articles and links on deleting cookies using JavaScript, I have encountered an issue where the JavaScript code does not seem to be functioning as expected. The code I utilized for setting cookie values using JavaScript is as follows:
var now = new Date();
var time = now.getTime();
time += 3600 * 1000;
now.setTime(time);
document.cookie="name=" + $scope.user.name;
document.cookie="email=" + $scope.user.email;
document.cookie ="expires=" + now.toGMTString();
Subsequently, in my attempt to remove the cookie, I employed the code provided in the following link from W3 Schools:
document.cookie = "name= ;email= ;expires=Thu, 01 Jan 1970 00:00:00 GMT";
Despite multiple attempts, the cookie persists and does not get deleted. I also tried an alternative method of setting the cookie value in the following manner:
document.cookie="name=" + $scope.user.name+";email=" + $scope.user.email+";expires=" + now.toGMTString();
Even after utilizing this method, the cookie remained undeleted. The discrepancy between the two approaches to assigning cookie values is evident, yet the issue of deletion persists. I have tested these codes on both Chromium
Version 50.0.2661.102 Ubuntu 16.04 (64-bit)
and Opera
Version: 37.0.2178.32
and in both instances, the cookie has not been successfully deleted. Additionally, it is worth noting that these two codes are being implemented within separate API calls.