오늘하루열지않기 팝업 오류 문의드립니다
레이어팝업을 오늘하루열지않기 눌러서 닫으면 그 시간 기점으로 24시간 카운팅이 되는데요
그냥 오늘하루열지않기 누르면 시간과 관계없이 오늘하루동안만 안열리게 하고 싶은데요
소스를 어떻게 바꾸어야 할까요?
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1; //options.path = "/";
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
$('.popup_01 input').click(function(e){
e.preventDefault();
$.cookie('popup_01', 'ck', { expires: 1 , path: '/' });
$(this).parents('.popup_wrap').hide();
});
현재는 이렇게 되어있습니다.
답변 2개
죄송합니다. 소스는 너무 길고 이해하기 어려워서 파악하지 못했습니다.
참고가 될까싶어 로직적인 얘기를 드립니다.
보통 팝업쿠키의 앞으로 24시간동안 열지 않기의 로직은,
유효기간이 24시간인 쿠키를 남기는 것입니다.
* popup_01 에 'ck' 값 저장
* popup_01 의 값이 'ck'값인지 체크하여 열기 또는 열지 않기
날짜기준으로 처리한다면 다음의 로직을 사용해 볼수도 있지 않을까라는 생각이 들었습니다.
쿠키값으로 금일 날짜를 저장하는 것입니다.
ex. popup_01 에 ck 를 저장하지 않고 '0402' (md) 남기기 (유효기간은 24시간으로 해도 무방합니다.)
체크하는 부분에서 popup_01 값이 있고, 그 값이 금일 날짜가 일치하면 '열지않기'로 하면 되지 않을까 합니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인