/**
* Класс JS cookie www.megabit24.ru
*/
function Cookie(){
this.get = function(name){
var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
this.set = function (name, value, expires) {
var path = '/';
var domain = location.hostname;
var secure = '';
var dat;
if (typeof expires == "number" && expires) {
var d = new Date();
d.setTime(d.getTime() + expires * 1000);
dat = d;
}
if (expires && expires.toUTCString) {
dat = dat.toUTCString();
}
document.cookie =
name +"=" + escape(value) +
((expires) ? "; expires=" + dat : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
}
this.del = function(name){
this.set(name, "",1);
}
} Пример использованияvar cookie = new Cookie();
cookie.set('backToCart','Y',1800);
cookie.get('backToCartMsg',);