팝업2개올리면 닫기버튼 안되요ㅜ
본문
<head>
<script language="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 closeWin() {
if ( document.notice_form.chkbox.checked ){
setCookie( "maindiv", "done" , 1 );
}
document.all['divpop'].style.visibility = "hidden";
}
//-->
</script>
</head>
<body>
<div id="divpop" style="position:fixed;left:10px;top:10px;z-index:200;visibility:hidden;">
<table width=300 height=400 cellpadding=2 cellspacing=0>
<tr>
<td style="border:1px #666666 solid" height=360 align=center bgcolor=white>
<img src="/cn/images/pop/popcn1.jpg" alt="">
</td>
</tr>
<tr>
<form name="notice_form">
<td align=right bgcolor=white>
<input type="checkbox" name="chkbox" value="checkbox">오늘 하루 이 창을 열지 않음
<a href="javascript:closeWin();"><B>[닫기]</B></a>
</td>
</tr>
</form>
</table>
<div id="divpop1" style="position:fixed;left:10px;top:10px;z-index:200;visibility:hidden;">
<table width=300 height=400 cellpadding=2 cellspacing=0>
<tr>
<td style="border:1px #666666 solid" height=360 align=center bgcolor=white>
<img src="/cn/images/pop/popcn1.jpg" alt="">
</td>
</tr>
<tr>
<form name="notice_form">
<td align=right bgcolor=white>
<input type="checkbox" name="chkbox" value="checkbox">오늘 하루 이 창을 열지 않음
<a href="javascript:closeWin();"><B>[닫기]</B></a>
</td>
</tr>
</form>
</table>
</div>
<script language="Javascript">
cookiedata = document.cookie;
if ( cookiedata.indexOf("maindiv=done") < 0 ){
document.all['divpop'].style.visibility = "visible";
}
else {
document.all['divpop'].style.visibility = "hidden";
}
cookiedata = document.cookie;
if ( cookiedata.indexOf("maindiv=done") < 0 ){
document.all['divpop1'].style.visibility = "visible";
}
else {
document.all['divpop1'].style.visibility = "hidden";
}
</script>
</body>
--------------------------------------------------------------------------------------------------
이런식으로 바꿔줬는데 팝업두개는 뜨는데 닫기가 먹통입니다.ㅠ
알려주시면 감사하겠습니다 ㅠㅠ
답변 2
1. 1번 div가 닫혀있지않았음
2. 코드상 1번 2번이 같은 쿠키를 생성하고 있었습니다.
3. 아래로 변경해 드렸습니다 올리신 html기준으로 변경 해드렸습니다
<head>
<script language="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 closeWin(a) {
if (document.all['notice_form'+a].checked==true ){
setCookie( "maindiv_"+a, "done" , 1 );
}
document.all['divpop_'+a].style.visibility = "hidden";
}
//-->
</script>
</head>
<body>
<div id="divpop_1" style="position:fixed;left:100px;top:10px;z-index:200;visibility:hidden;">
<table width=300 height=400 cellpadding=2 cellspacing=0>
<tr>
<td style="border:1px #666666 solid" height=360 align=center bgcolor=white>
<img src="/cn/images/pop/popcn1.jpg" alt="">
</td>
</tr>
<tr>
<td align=right bgcolor=white>
<input id='notice_form1' type="checkbox" name="chkbox" value="checkbox">오늘 하루 이 창을 열지 않음
<a href="javascript:closeWin(1);"><B>[닫기]</B></a>
</td>
</tr>
</table>
</div>
<div id="divpop_2" style="position:fixed;left:200px;top:10px;z-index:200;visibility:hidden;">
<table width=300 height=400 cellpadding=2 cellspacing=0>
<tr>
<td style="border:1px #666666 solid" height=360 align=center bgcolor=white>
<img src="/cn/images/pop/popcn1.jpg" alt="">
</td>
</tr>
<tr>
<td align=right bgcolor=white>
<input id='notice_form2' type="checkbox" name="chkbox" value="checkbox">오늘 하루 이 창을 열지 않음
<a href="javascript:closeWin(2);"><B>[닫기]</B></a>
</td>
</tr>
</table>
</div>
<script language="Javascript">
cookiedata = document.cookie;
if ( document.cookie.indexOf("maindiv_1=done") < 0 ){
document.all['divpop_1'].style.visibility = "visible";
}
else {
document.all['divpop_1'].style.visibility = "hidden";
}
cookiedata = document.cookie;
if ( document.cookie.indexOf("maindiv_2=done") < 0 ){
document.all['divpop_2'].style.visibility = "visible";
}
else {
document.all['divpop_2'].style.visibility = "hidden";
}
</script>
</body>
!-->
닫기 처리하는 부분이 동일한 id를 쓰고 있으면 안되는 부분이니 참고해서 적용해 주세요