상단띠배너 24시간닫기 관련 질문입니다
본문
메인, 서브페이지, 게시판, 로그인 페이지 전부 같은 head.php 파일을 사용하고 있는데
서브페이지에서 상단띠배너 X버튼을 클릭해서 닫으면 쿠키가 생성되며 다시 열리지 않는데 게시판/로그인 페이지는 쿠키가 생성이 안되어있어 띠배너가 나타납니다.
이후 게시판/로그인 페이지에서 띠배너를 닫아야지만 쿠키가 생성되며 다시 열리지 않습니다.
서브페이지와 게시판/로그인 페이지가 쿠키를 공유하지 않는것같은데 해결방법이 없을까요?
<!--헤드팝 스크립트-->
<!--X버튼 클릭시 24시간 이후 다시 뜨게-->
<script>
// 쿠키 가져오기
var getCookie = function (cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
}
return "";
}
// 24시간 기준 쿠키 설정하기
var setCookie = function (cname, cvalue, exdays) {
var todayDate = new Date();
todayDate.setTime(todayDate.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + todayDate.toUTCString(); // UTC기준의 시간에 exdays인자로 받은 값에 의해서 cookie가 설정 됩니다.
document.cookie = cname + "=" + cvalue + "; " + expires;
}
var couponClose = function(){
setCookie("close","Y",1); //기간( ex. 1은 하루, 7은 일주일)
$(".headpop").hide();
$(".headpop_x_bnt").hide();
$(".headpop").animate({opacity:0,width:"0%",height:"0%"});
$("#hd").animate({margin:"0"});
}
$(document).ready(function(){
var cookiedata = document.cookie;
if(cookiedata.indexOf("close=Y")<0){
$(".headpop").show();
$(".headpop_x_bnt").show();
$("#hd").css({marginTop:"12.7%"});
}else{
$(".headpop").hide();
$(".headpop_x_bnt").hide();
}
$(".headpop_x_bnt").click(function(){
couponClose();
});
});
</script>
<!--헤드팝 스크립트-->
<a href="javascript:void()">
<img class="headpop_x_bnt" src="../img/close_btn.gif" alt="" style="position:fixed;z-index:100000001;top:20px;right:20px;width:1.5%;filter: brightness(40%);display:none;" title="">
</a>
<a href="../sub/0202.php">
<img src="../img/headpop.png" class="headpop" alt="" style="width:100%;height:auto;position:fixed;top:0;z-index:9999;display:none;">
</a>
<div id="hd" style="position:relative;width:100%;z-index:1000;top:0;"></div>
답변을 작성하시기 전에 로그인 해주세요.