-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie.js
28 lines (28 loc) · 1.13 KB
/
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
/* 原作:https://qa.1r1g.com/sf/ask/1257635361 */
var cookieToday = new Date();
var expiryDate = new Date(cookieToday.getTime() + (1 * 86400000));
function setCookie(name, value, expires, path, theDomain, secure) {
value = escape(value); var theCookie = name + "=" + value +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((theDomain) ? "; domain=" + theDomain : "") +
((secure) ? "; secure" : ""); document.cookie = theCookie;
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
var offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
var end = document.cookie.indexOf(";", offset)
if (end == -1) end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
function delCookie(name, path, domain) {
if (getCookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-70 00:00:01 GMT";
}