-
Notifications
You must be signed in to change notification settings - Fork 17
/
JY.cookie.js
49 lines (49 loc) · 1.32 KB
/
JY.cookie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
* JY javascript库,版本号:1.0
* http://www.lovewebgames.com
* Copyright 2012, 田想兵
* Email : [email protected]
* QQ:55342775
*Cookie
* Date: 2012/7/11
*/
JY.cookie=function(name,value,prop){
var c = document.cookie, ret=null;
if (arguments.length ==1){
if (c && c!==''){
var cookies =c.split(';');
for (var i=0,l=cookies.length; i<l ;i++ ){
var cookie = JY.trim( cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
ret = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
}else{
prop = prop||{};
var expires= '';
if (prop.expires){
var date;
switch(prop.expires.constructor){
case Number :{
date = new Date();
date.setTime(date.getTime() + (prop.expires*1000*60*60*24) );
date =date.toUTCString();
}break;
case String:{
date = prop.expires;
}break;
default:{
date = prop.expires.toUTCString();
}break;
}
expires = '; expires=' + date;
}
var path = prop.path ? '; path=' + (prop.path) : '';
var domain = prop.domain ? '; domain=' + (prop.domain) : '';
var secure = prop.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
return ret;
}