자바스크립트 쿠키 제어 함수

// http://www.qindex.info/Q_frame.php?s_clss=board&s_prcss=thrd&s_tmplt=&s_brd=5&s_thrd=33

function Q_getDateOfExpire(year,day,hour,minute,second) {
var today = new Date();
var exprs = new Date();
exprs.setTime( today.getTime()
+1000*60*60*24*365*year
+1000*60*60*24 *day
+1000*60*60 *hour
+1000*60 *minute
+1000 *second );
return exprs;
}

/*
String name, value
Date expires
String path, domain
Boolean secure

optional: expires,path,domain,secure
*/
function Q_setCookie(name,value,expires,path,domain,secure) {
document.cookie = name + '=' + escape(value) + ';'
+ ((expires) ? ' expires=' + expires.toGMTString() + ';' : '')
+ ((path) ? ' path=' + path + ';' : '')
+ ((domain) ? ' domain=' + domain + ';' : '')
+ ((secure) ? ' secure' + ';' : '');
}

// Returns a string or false
function Q_getCookie(name) {
var srch = name + '=';
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(srch);
if (offset != -1) {
offset += srch.length;
end = document.cookie.indexOf(';', offset);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
} else return false;
} else return false;
}

// optional: path,domain
function Q_deleteCookie(name,path,domain) {
if (Q_getCookie(name))
document.cookie = name + '=;'
+ ' expires=Thu, 01-Jan-70 00:00:01 GMT;'
+ ((path) ? ' path=' + path + ';' : '')
+ ((domain) ? ' domain=' + domain + ';' : '');
}
댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2.11
2.12
2.13
2.14
2.15
2.16
2.17
2.18
2.19
2.20
2.21
2.22
2.23
2.24
2.25
2.26
2.27
2.28