viiprogrammer Posted April 10, 2015 Report Share Posted April 10, 2015 Не так давно наткнулся на очень хороший плагин облегчающий работу с cookie Вот сам плагин: jquery.cookie.rar И так теперь научимся с ним работать: Устанавливаем cookie $.cookie('Имя', 'Значение'); Иногда требуется поставить cookie на несколько дней это будет так $.cookie('Имя', 'Значение', { expires: кол-во дней }); Cookie для определённой части сайта можно установить так: $.cookie('Имя', 'Значение', { expires: 5, path: 'Путь', }); Получение cookie var test = $.cookie('Имя'); Удаление cookie $.cookie('cookie_name', null); 3 Quote Link to comment Share on other sites More sharing options...
JacksScripts Posted April 10, 2015 Report Share Posted April 10, 2015 Полезная штука, ща плеер новый пишу, пользуюсь куками только так! Я считаю в серьезных проектах нужна эта вещь! 1 Quote Link to comment Share on other sites More sharing options...
viiprogrammer Posted April 10, 2015 Author Report Share Posted April 10, 2015 Полезная штука, ща плеер новый пишу, пользуюсь куками только так! Я считаю в серьезных проектах нужна эта вещь! Я как увидел её сразу се прицепил удобная Quote Link to comment Share on other sites More sharing options...
Why Not Posted July 7, 2016 Report Share Posted July 7, 2016 На мой движок по-любому надо ставить Quote Link to comment Share on other sites More sharing options...
Mario Posted July 7, 2016 Report Share Posted July 7, 2016 На мой движок по-любому надо ставить cookies = { cookies: null, set: function (name, value, days) { if (!this.cookies) this.init(); this.cookies[name] = value; 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 = name + "=" + value + expires + "; path=/"; }, get: function (name) { if (!this.cookies) this.init(); return this.cookies[name]; }, init: function () { this.cookies = {}; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i].split("="); if (c.length == 2) this.cookies[c[0].match(/^[\s]*([^\s]+?)$/i)[1]] = c[1].match(/^[\s]*([^\s]+?)$/i)[1]; } } }; И ничего больше, еще и библиотеки подключать ради этого. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.