Skip to content

Instantly share code, notes, and snippets.

@claudiainbytes
Created April 2, 2020 01:08
Show Gist options
  • Save claudiainbytes/74de891c04d2ca703625a32157ae410a to your computer and use it in GitHub Desktop.
Save claudiainbytes/74de891c04d2ca703625a32157ae410a to your computer and use it in GitHub Desktop.
// Cookie for current question
function create_cookie(name, value, days2expire, path) {
var date = new Date();
date.setTime(date.getTime() + (days2expire * 24 * 60 * 60 * 1000));
var expires = date.toUTCString();
document.cookie = name + '=' + value + ';' + 'expires=' + expires + ';' + 'path=' + path + ';';
}
function retrieve_cookie(name) {
var cookie_value = "",
current_cookie = "",
name_expr = name + "=",
all_cookies = document.cookie.split(';'),
n = all_cookies.length;
for(var i = 0; i < n; i++) {
current_cookie = all_cookies[i].trim();
if(current_cookie.indexOf(name_expr) == 0) {
cookie_value = current_cookie.substring(name_expr.length, current_cookie.length);
break;
}
}
return cookie_value;
}
function delete_cookie(name) {
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment