function GetCookie(key) {
var arg = key + "=";
var argLength = arg.length;
var cookieLength = document.cookie.length;
var i = 0;
var j = 0;
while (i < cookieLength) {
j = i + argLength;
if (document.cookie.substring(i, j) == arg) {
var endString = document.cookie.indexOf(";", j);
if (endString == -1) {
endString = document.cookie.length;
}
return unescape(document.cookie.substring(j, endString));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) {
break;
}
}
return null;
}
function SetCookie(key, value) {
var argv = arguments;
var argc = arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var domain = (argc > 3) ? argv[3] : null;
var path = (argc > 4) ? argv[4] : '/';
var secure = (argc > 5) ? argv[5] : false;
if (expires != null) {
var date = new Date();
date.setTime(date.getTime() + (expires * 24 * 60 * 60 * 1000)) //days
expires = date;
}
document.cookie = key + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
}
반응형
'개발 > Javascript' 카테고리의 다른 글
Javascript C# String.Format 메서드와 동일한 기능 (0) | 2022.01.18 |
---|---|
jQuery selector like 검색 (0) | 2022.01.17 |
Javascript Html 인코딩, 디코딩 (0) | 2022.01.07 |
c# API 로 JsTree 랜더링 (0) | 2021.12.26 |
JsTree Contextmenu(Create, Rename, Delete) 활용하기 (0) | 2021.12.26 |
댓글