Create Cookie Function with Vanilla JS
Easily create cookies with vanilla javascript.
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
Written by Montana Flynn
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Client
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#