Friday, February 24, 2023

Cookie Vanilla Javascript


 

1. Set Cookie

 document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

2. Get Cookie

let cookie = {};

        var a = document.cookie.split(';');

        for(var i=0; i<a.length; i++){

            var b = a[i].split('=');

                var [key, value]  = b;

                cookie[key.trim()] = value;

        }

  console.log(cookie['_ga']);

3. ChangeCookie 

document.cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

No comments:

Post a Comment

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...