Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/28cb6ab91b68b3819625 to your computer and use it in GitHub Desktop.
Save steveosoule/28cb6ab91b68b3819625 to your computer and use it in GitHub Desktop.
Set Cookies in JavaScript like PHP
// FROM: http://snippetrepo.com/snippets/set-cookies-in-javascript-like-php
function set_cookie(name, value, time, path) {
var date = new Date();
date.setTime(date.getTime() + (time * 1000));
var expires = ';expires='+ date.toGMTString();
document.cookie = name +'='+ value + expires +';path='+ path;
}
$(document).on('click', '.set-cookie', function() {
set_cookie('test', null, 3600, '/');
});
$(document).on('click', '.unset-cookie', function() {
set_cookie('test', null, -3600, '/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment