[JS] 오늘 하루 그만 보기 레이어(+윈도우창)

1)
- CSS
a{text-decoration:none; color:white}
.pull-right{float:right}
.main_popup{width:350px; height:430px; border:3px solid #3E4156;background-color: white;}
.popup_bottom{
    background-color: #3E4156;
    color: white;
    height: 25px;
    padding: 2px 10px 3px 10px;
    width:330px;
}
- JS
if(getCookie("notToday")!="Y"){
$("#main_popup").show('fade');
}

function closePopupNotToday(){          
setCookie('notToday','Y', 1);
$("#main_popup").hide('fade');
}
function setCookie(name, value, expiredays) {
var today = new Date();
   today.setDate(today.getDate() + expiredays);

   document.cookie = name + '=' + escape(value) + '; path=/; expires=' + today.toGMTString() + ';'
}

function getCookie(name)
{
    var cName = name + "=";
    var x = 0;
    while ( x <= document.cookie.length )
    {
        var y = (x+cName.length);
        if ( document.cookie.substring( x, y ) == cName )
        {
            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 "";
}
function closeMainPopup(){
$("#main_popup").hide('fade');
}

- Html

<div id="main_popup" class="main_popup" style="position: absolute; z-index:10000; top:0px; left:0; display: none;">
<a href="" ><img src="" style="width:100%;height:400px;"/></a>
<div class="popup_bottom">
<a href="javascript:closePopupNotToday()" class="white">오늘하루 그만보기</a>
<a class="pull-right white" href="javascript:closeMainPopup();">닫기</a>
</div>
</div>


2)
: 부모창
//메인 팝업 S
$(document).ready(function($) {
function getStrNo(str) {
if(str < 10) {
return "0"+str;
} else {
return str;
}
}
var now = new Date();
var today = now.getFullYear()+''+getStrNo((now.getMonth()+1))+''+getStrNo(now.getDate());
var sday = 20170706;
var eday = 20181107;
if(sday<=today && eday>today){
mainPopop();
}

/*var checkSKBGTM_yn = 'Y';
console.log('로그인: '+checkSKBGTM_yn);

if(checkSKBGTM_yn == 'Y'){
mainPopop();
}*/
});

function mainPopop(){
    function getCookie(name){
        var nameOfCookie = name + "=";
        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 "";
    }
    if (getCookie("popname") != "done"){
        var popUrl = "/html/MainPopup_180706.html";
        var popOption = "width=500px, height=500px, resizable=no, scrollbars=no, status=no;";
        window.open(popUrl,"",popOption);
    }
}
//메인 팝업 E

: 자식창
<script>
function setCookie(name, value, expiredays){
    var todayDate = new Date();
        todayDate.setDate (todayDate.getDate() + expiredays);
        document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";";
    }
function closePop(){
    var _todayClose = $('#todayClose');
if (_todayClose.is(":checked")){
        setCookie("popname", "done", 1);
    }
self.close();

 
</script>


<div>
메인팝업테스트
<br />
<label><input type="checkbox" onClick="closePop();" id="todayClose"> 하루동안 이 창을 보지 않습니다.</label>
<button type="button" onclick="self.close();" title="팝업 닫기">창닫기</button>
</div>

댓글

이 블로그의 인기 게시물

[iOS] body 스크롤 막기

[html] 모바일웹 작업 팁 정리중...

Swiper lazyLoading