Good afternoon!
Interested in the question, is it possible to create and read cookies without having an SSl certificate, that is, an HTTPS connection? I tried to do this:

 document.cookie = "Hello=World"; 

But cookies in the browser did not appear. Thanks in advance for your help!
And is it possible to create cookies in some way if the html file is local?

  • How was it checked that the cookies did not appear? - Grundy
  • all cookies on this site looked - ZeroBone
  • @ZeroBone, is it read.javascript.ru/cookie ? - Visman
  • @ZeroBone, how exactly did you look? - Grundy
  • read, did not help - ZeroBone

2 answers 2

It is strange that you do not work, because I have a document.cookie = "username=John Doe"; command document.cookie = "username=John Doe"; and document.cookie work fine:

create a cookie

get all the cookies

Perhaps there are any restrictions in the environment where you work / check? Cook life time for example. It should also be borne in mind that cookies use server time (may differ from client time).

  • Something I have doubts arise that js uses server time to install cookies in the browser. - Visman
  • @Visman Reasonable remark, but I just gave an example to think about the problem. - Siarhey Uchukhlebau

Apparently the main question is the following:

And is it possible to create cookies in some way if the html file is local?

The answer to this question depends on the browser. For example, in Chrome - the ability to use cookies for local files is disabled by default. But this setting can be turned off using the flag: --enable-file-cookies

For the reverse example: in the EDGE browser, the code in question also works for a local file.

The rest of the code given in the question is quite working.