Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

create cookie javascript react

createCookieInHour: (cookieName, cookieValue, hourToExpire) => {
    let date = new Date();
    date.setTime(date.getTime()+(hourToExpire*60*60*1000));
    document.cookie = cookieName + " = " + cookieValue + "; expires = " +date.toGMTString();
},

//create any new cookie 
createCookieInHour('cookieName', 'cookieValue', 5);

//view cookies
let cookie = document.cookie.split(';');
console.log('cookie : ', cookie);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #cookie #javascript #react
ADD COMMENT
Topic
Name
2+1 =