Setting a Cookie Value in the Browser

function setCookie(name, value, days) {   var date = new Date();   date.setTime(date.getTime()+(days*24*60*60*1000));   var expires = "; expires="+date.toGMTString();   document.cookie = name + "=" + value +                     expires + "; path=/"; }

To add a new cookie for your web site, set document.cookie = "name=value; expireDate; path;";. The expire date needs to be a date set using .toGMTString(), and the path is the path on your web site that the cookie applies to.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.