본문 바로가기
IT 인터넷

[스크립트] 오늘 하루 이 창을 열지 않음

by zzom~ 2024. 8. 30.
반응형

01.. 아래의 스크립트를 head 사이에 넣는다..

<script>
       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 pop(){
                 if(getCookie("openevent") != "done"){
                       winopen = window.open('open.htm','','width=350,height=480,status=no,scrollbars=no');
                       winopen.focus();
                       }
               }
</script>

 
02.. body 태그안에 onload="pop();" 을 삽입한다..

<body onload="pop();">

 
03.. 새창을 띄울 페이지 head 사이에 아래의 스크립트를 넣는다..

<script language="JavaScript">
<!-- JavaScript
function setCookie( name, value, expiredays )
 {
   var todayDate = new Date();
   todayDate.setDate( todayDate.getDate() + expiredays );
   document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
 }
function closeWin2()
 {
   if ( document.notice_form.chkbox.checked ){
     setCookie( "openevent", "done" , 1 );
   }
   self.close();
 }

// - JavaScript - -->
</script>

 
04.. 새창의 body의 원하는 위치에 아래의 소스를 넣는다.

<form name="notice_form">
오늘 하루 이창을 열지 않음<input type="checkbox" name="chkbox" value="0" onclick="closeWin2();">
</form>
반응형