아래 질문을 드린 스크립트에 쿠키를 추가해 주고 싶습니다.
<script>
jQuery(document).ready(function($) {
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = 1010;
//Set heigth and width to mask to fill up the whole screen
$('#mask').css('width', maskWidth);
$('#mask').css('height', maskHeight);
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("slow",0.9);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>
<div id="boxes">
<div id="dialog" class="window">
Your Content Goes Here
<div id="popupfoot"> <a href="#" class="agree">I agree</a> | <a class="close agree"style="color:red;" href="#">I do not agree</a> </div>
</div>
<div id="mask"></div>
</div>
#mask(배경) 을 클릭하거나 혹은 "i do not agree" 를 클릭해도 팝업이 닫히게 하면서 쿠키를 적용해서 1일 동안 같은 문서에 접속시 팝업이 안뜨게 하고 싶습니다.
물론 다른 문서에서 조건이 맞으면 팝업은 다시 떠야 하구요.
댓글 9
<script>
jQuery(document).ready(function($) {
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = 1010;
//Set heigth and width to mask to fill up the whole screen
$('#mask').css('width', maskWidth);
$('#mask').css('height', maskHeight);
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("slow",0.9);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
//if close button is clicked
$('.window .close').click(function(e){
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
// 게시글 별 쿠키 확인
var documentSrl = new URL(current_url).searchParams.get('document_srl');
$("#dialog .agree").click(function(e){
e.preventDefault();
setCookie('agree_cookie_' + documentSrl, 'true', new Date(Date.now() + 86400));
$('#boxes').remove();
});
if(getCookie('agree_cookie_' + documentSrl) == 'true'){
$('#boxes').remove();
}
else {
$('#boxes').show();
}
});
</script>
<div id="boxes" style="display: none;">
<div id="dialog" class="window">
Your Content Goes Here
<div id="popupfoot"> <a href="#" class="agree">I agree</a> | <a class="close"style="color:red;" href="#">I do not agree</a> </div>
</div>
<div id="mask"></div>
</div>
위 코드를 사용하시면 I agree 클릭시에만 쿠키에 저장합니다.
I do not agree 에도 쿠키 저장하시려면 해당 태그에 agree 클래스를 추가하시면 됩니다.
답변 감사합니다. 저는 반대로 I do not agree 에 쿠키를 적용하려고 합니다.
i agree 를 누를경우 조건때문에 팝업이 뜨지 않게 변동 되거든요. 시도해보겠습니다.
.close를 이용하면 될 것 같군요.
감사합니다. i do not agree 클릭시 쿠키로 인해 팝업이 다시 뜨지 않게 잘 처리되었습니다.
그런데 배경을 클릭시 창이 사라질 경우는 적용이 안되는 듯 합니다.
아.. 배경 id 가 잘못되어 있는 것 같네요. 확인하겠습니다.엇.. 배경 id 문제가 아닌가요... 잘 안되네요..
배경쪽에도 agree 클래스를 추가해 주시면 될겁니다.
id="mask" class="agree" 처럼요.
그런데 혹시 시간이 뭔가 오류가 있을까요? 1-2분 후에 쿠키가 만료되는 것 같습니다.
이부분이 id mask 는 반영하지 못하지 않나요 ?
도움 감사합니다. 기능이 모두 구현이 되었네요. 디자인만 다듬어서 완성하면 되겠습니다.