Question

Im doiing a web app and Im already in the part where theuser has an option to change the language of the app, ex. from en-US to ja, I'm using i18next. What I did was write the user's preferred language to cookie, reload the page, and read the cookie I created with the user's preferred lang. however it doest work because it seems that everytime you reload the page, the cookie that I created is deleted, so it reverts back to the default lang.

The question is there a way to reload the page without deleting the cookie that I made?

Was it helpful?

Solution

Try setting an expiry date on the cookie. Code below sets it one year in the future.

a = new Date(new Date().getTime() +1000*60*60*24*365);
document.cookie = 'mycookie=somevalue; expires='+a.toGMTString()+';'; 

Please give it a shot and check the resources tab again to see if it's changed.

Here is some info regarding cookie syntax and options.

OTHER TIPS

This might happen while development time, once you deploy the app it may not occur.

please deploy the app into local IIS and test it weather you facing same problem.

also hope you added expiry time for cookie. its some thing like below

HttpCookie aCookie = new HttpCookie("SiteLanguage");
aCookie.Value = "en-US";
aCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(aCookie);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top