Cookie
팝업창 제어
cookie.js
function getCookie(name) {
var Found ;
Found = false ;
var start, end ;
var i = 0 ;
while (i <= document.cookie.length) {
start = i ;
end = start + name.length ;
if(document.cookie.substring(start, end) == name) {
Found = true ;
break ;
}
i++ ;
}
if(Found == true) {
start = end + 1 ;
end = document.cookie.indexOf(';', start) ;
if(end < start)
end = document.cookie.length ;
return document.cookie.substring(start, end) ;
}
return false ;
}
function setCookie(name, value, expire_days) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expire_days);
var c_value = escape(value) + ((expire_days == null) ? '' : '; expires=' + exdate.toUTCString());
document.cookie = name + '=' + c_value;
}
창 열기
// 이벤트 페이지 popup
if (getCookie('cookie_name') != 'true') {
window.open ('popup.html', 'popup_window_name', 'width=400, height=500');
}
팝업창 버튼
function controlCookie(cookie_name, el) {
if (el.checked) {
setCookie(cookie_name,"true", 1);
}
else {
setCookie(cookie_name,'', 1);
}
return;
}
<div align="center">
<input type="checkbox" name="checkbox" onclick="controlCookie('cookie_name', this)">
오늘 하룻동안 이창을 띄우지 않습니다.
</div>