Answer the question
In order to leave comments, you need to log in
Why are cookies saved in this form?
I save cookies like this:
var l = e.currentTarget.dataset.lang,
expires = "",
date = new Date();
date.setTime(date.getTime() + (360*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
document.cookie = 'language' + "=" + l + expires + "; path=/";
language = d725e8fc6e6a3c9370602caf9b8157cfc1f69ba22fdef33654c57f769a7f9012a%3A2%3A%7Bi%3A0%3Bs%3A8%3A%22language%22%3Bi%3A1%3Bs%3A2%3A%22en%22%3B%7D
Answer the question
In order to leave comments, you need to log in
If you manually set element.dataset.lang , then that is where the error lies. You probably initially write such a wild value in the data-lang of your element.
If we are talking about the language, then you can take it from html , that is, document.documentElement.lang , something like this:
var l = document.documentElement.lang,
expires = "",
date = new Date();
date.setTime(date.getTime() + (360*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
document.cookie = 'language' + "=" + l + expires + "; path=/";
// "language=ru; expires=Sat, 18 Aug 2018 20:30:14 GMT; path=/"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question