- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
// *******************************************************
// Cookie helper functions
// *******************************************************
// get cookie
function getCookie(cookie_name){
var regex = new RegExp('(^|;\\s)'+cookie_name+'=([^;]+)', 'i');
return (document.cookie.match(regex) || [])[2];
}
// set cookie for 30 days
function setCookie(name, value){
var exp = new Date(Date.parse(new Date()) + (30*24*60*60*1000));
var domain = window.location.hostname.replace(/www/i,''); // domain isolation is tricky, so this will cover the majority of use cases
document.cookie = name+'='+value+'; path=/; expires='+exp+'; domain='+domain;
}
// delete cookie
function deleteCookie(name) {
var domain = window.location.hostname.replace(/www/i,'');
document.cookie = name+'=; domain='+domain+'; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}