프로그래밍/javascript

오늘 하루 팝업창 띄우지 않기

antilla 2011. 1. 18. 16:15


1.부모창 부분

<script type="text/javascript">

//이 부분부터 수정할 필요 없음

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 popup(){

 if(getCookie("Notice") != "no"){    // 쿠키네임지정
  var child = null;

  child = window.open("/popup/member_drop_popup.jsp", "pop", 
   "width=650,height=500,notoolbars,resizable=no,scrollbars=auto");     //팝업 띄울 페이지 디렉토리 혹은 팝업창 웹페이지
  child.focus();
  }
 return;
 }
 popup();          //자동으로 팝업 띄우기

</script>


2.팝업창 부분

function setCookie( name, value, expiredays )
{
var todayDate = new Date();
todayDate.setDate( todayDate.getDate() + expiredays );
document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
function closeWin()
{
if ( document.frm.Notice.checked )
setCookie( "Notice", "no" , 1);              //부모창에서 지정한 쿠키네임
self.close();
}

<input type="checkbox" name="Notice" value="열지않음"> 오늘 하루동안 이창을 열지 않음 <a href="#" onclick="javascript:closeWin();"> <font color="red"><b>[창닫기]</font></b></a>