Permalink
Browse files

Merge pull request #2 from zim32/master

Add duration param
  • Loading branch information...
2 parents d340141 + 88b847d commit 848efd8765ebdae4acba662c25cf15fb3ee33a92 hck committed Oct 29, 2011
Showing with 3 additions and 2 deletions.
  1. +3 −2 jquery.cookie.js
View
@@ -9,7 +9,7 @@
*/
(function($){
- $.cookie = function(name, val) {
+ $.cookie = function(name, val, duration) {
var trim = function(str){
return str.replace(/(^\s+)|(\s+$)/g, '');
};
@@ -28,7 +28,8 @@
if(!name) return cookies;
- if(val) document.cookie = name + '=' + encodeURIComponent(val);
+ var expires = duration?new Date(new Date().getTime() + duration*1000).toGMTString():false;
+ if(val) document.cookie = name + '=' + encodeURIComponent(val) + ((expires)?'; expires=' + expires:'');
else return cookies[name];
return $;

0 comments on commit 848efd8

Please sign in to comment.