skip to Main Content

I Can’t Make A Cookie In An Html File…

document.cookie = "Lang:Ar";

When It’s Time To Preview:

In Inspect Section > Console :

document.cookie
''

So I Tried To Turn The Cookie Into A Function :

function SetCookie(Key,Val) {
    document.cookie = Key + "=" + Val;
}

But It Didn’t Success…

1.Creating The Cookie :

SetCookie("Lang","Ar");
"Lang", "Ar"

2.Previewing It :

document.cookie
''

The Same Thing 😭

But It Worked Only On LiveServer In VScode.

2

Answers


  1. Personnally I’m using this:

    cookieStore.set("cookieName", "cookieValue");
    

    (It only works if you access the document in HTTP or HTTPS)

    You should look at Mamp or Xamp for learning a bit about serving your code locally

    Here is a step by step guide on how to install XAMPP:
    https://www.youtube.com/watch?v=VCHXCusltqI

    Login or Signup to reply.
  2. If you are working entirely on the front-end, you can use WebStorage.

    With WebStorage, you have two options:


    Example:

    You can use localStorage as follows:

    localStorage.setItem('Lang', 'Ar');
    
    localStorage.getItem('Lang'); // Ar
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search