본문 바로가기

popup + cookie

cookie 이용 팝업을 띄우고 하루 동안 띄우지 않기 체크


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 "";
}
 
function fnToDateTime() {
    var today = new Date(); // 날짜 변수 선언
    var timeNow  = fnLPAD(String(today.getHours()),"0",2+ fnLPAD(String(today.getMinutes()),"0",2); // 시간을 구함(HHMM : 24H)
    var dateNow  = fnLPAD(String(today.getDate() ),"0",2); // 일자를 구함
    var monthNow = fnLPAD(String((today.getMonth()+1)),"0",2); // 월(month)을 구함
    var yearNow  = String(today.getFullYear()); // 년(year)을 구함
    var dd = yearNow + monthNow + dateNow + timeNow;
    return dd;
}
 
function infoPopup() {
    if(getCookie("popup_20190429")!="no"){
        var today = fnToDateTime();            
        if (today > "201904190900" && today < "201905082359"){
             var child = null;
             child = window.open("<c:url value='/popup/popup_20190429.html' />""popup_20190429""width=600, height=610, scrollbars=no, resizable=no, top=0, left=0");
             child.focus();
        }
    }
    return "";
}
 
function setCookie(name, value, expiredays){
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
cs




END