The title explains the whole problem, I included the OS and browser in case that makes a difference. The code is very simple:
alert(cookieString); // path=/;domain=http://localhost:3000/;expires=Fri May 01 2020 16:29:34 GMT-0400 (Eastern Daylight Time);email=test.email@emailservice.com;password=test password;
document.cookie = cookieString;
alert(document.cookie); // Empty
window.location.replace("http://localhost:3000/main.html");
I don't understand why the alert for the document.cookie
is empty when the cookieString
variable clearly has a valid cookie in it which I am trying to set. At first, I thought the redirect was to blame, so I then put it in a window.setTimeout
, and set it to wait for 5 seconds, thinking that the browser needed time to get the cookie set. This theory did not work however, then I completely removed the redirect, and it still gave me the same output. So I then tried and experimenting with cookies in the console, when I entered the following code into the console:
document.cookie = "Test Cookie";
It worked just fine, despite not using the correct format. The fact that it works in the console and not in my code makes me think its something related to permissions, but I really don't know.
Any help would be appreciated, Thanks!