본문 바로가기
JavaScript

[JavaScript] 팝업

by Yeoseungwon 2024. 2. 16.
728x90
<div class="popup" id="popup1" style="left: 4%;">
		<a>
			<img src="images/img/pop_240216.png" width="700" alt="" />
		</a>
		<div class="popupFooter">
			<div class="notOpen" style="margin-top: 7px;">
				<label style="margin-right: 6px; cursor: pointer;">
				<input type="checkbox" name="chkClose" id="popup1_notToday" class="pbtn cbtn" style="display: inline-block; -webkit-appearance: checkbox;" title="닫기"> 오늘 하루 이 창을 열지 않음</label>
				<a href="javascript:close_popup('popup1');" style="padding-right: 10px; cursor: pointer;">[닫기]</a>
			</div>
		</div>
	</div>
.popup p span{font-size:20px}
#popup1, #popup2, #popup3, #popup4 {
	position: absolute;
	top: 7%;
	max-width: 400px;
    width: 78%;
	height: auto;
	padding: 10px;
	border: 1px solid rgb(221, 221, 221);
	background: rgb(255, 255, 255);
	box-shadow: 2px 2px 6px #666;
	display: none;
}
$(document).ready(function(){
	var popupTime = new Date();
	var y = new Date().getFullYear();
	var m = new Date().getMonth() + 1;
	var d = new Date().getDate();
/* 	var h = new Date().getHours();
	var mm = new Date().getMinutes(); */
	var popupTime = y + ""+ (m<10?'0'+m:m) +""+ (d<10?'0'+d:d);
	//+(h<10?'0'+h:h)+""+(mm<10?'0'+mm:mm);
	// console.log(popupTime);
	
	for(i=1; i<7; i++){
		var cookieName = "popup" + i + "_notToday";
		
		if(getCookie(cookieName)){
			$("#popup"+i).css('display', 'none');
		} else{
			$("#popup"+i).css('display', 'block');
		}
		$("#popup"+i).css('z-index', '9999'- i);
	}
	/* if(popupTime >= '20230601'){
		$("#popup3").css('display', 'none');
	} */

});
function close_popup(id) {
	var targetNotTodayBox = id + "_notToday";
	console.log(targetNotTodayBox); //확인
	if ($("#" + targetNotTodayBox).prop("checked")) {
		setCookie(targetNotTodayBox, 'Y', 1);
		console.log("setted cookie");
	} 
	$("#" + id).fadeOut();
}

//쿠키 세팅
function setCookie(xname, xvalue, expiredays) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = xname + "=" + escape(xvalue) + "; path=/; expires=" + todayDate.toGMTString() + ";";
	console.log(document.cookie);
}

// 쿠키 존재 여부 확인
function getCookie(cookieName) {
    var nameOfCookie = cookieName + "=";
    var x = 0;
    while (x <= document.cookie.length ) {
        var y = (x+nameOfCookie.length);
        if(document.cookie.substring(x, y) == nameOfCookie) {
            if((endOfCookie = document.cookie.indexOf( ";", y )) == -1)
                endOfCookie = document.cookie.length;
            return unescape(document.cookie.substring(y, endOfCookie));
        }
        x = document.cookie.indexOf( " ", x ) + 1;
        if (x == 0)  break;
    }
    return "";
}
728x90

'JavaScript' 카테고리의 다른 글

ajax post - controller return값  (0) 2024.11.07
[JavaScript] 팝업 날짜 지정  (0) 2024.02.22
[JavaScript] 이미지 슬라이드 소스  (1) 2023.12.05
[Swiper] 라이브러리 포커스이동  (0) 2023.11.17
[JavaScript] onkeydown  (0) 2023.10.24