대부분 플러그인을 쓰다가 일반페이지(그누보드가 없는 사이트)에서 쓸일이 있어서
다음과 같은 소스로 셋팅했는데.. 팝업이 계속 뜨네요 한번 봐주세요~
메인 페이지
[code]
<!-- 2011년 05월 20일 팝업 추가 -->
<script language="javascript">
//쿠키값을 가져오는 함수
function getCookie(name) {
var from_idx = document.cookie.indexOf(name+'=');
if (from_idx != -1) {
from_idx += name.length + 1
to_idx = document.cookie.indexOf(';', from_idx)
if (to_idx == -1) {
to_idx = document.cookie.length
}
return unescape(document.cookie.substring(from_idx, to_idx))
}
}
//getCookie 함수를 호출하여 쿠키값을 가져온다.
var blnCookie = getCookie("member_gender");
//쿠키값이 true가 아닐 경우에만 새 창을 띄운다.
if ( !blnCookie ) {
window.open
("./event.html","_blink","width=620,height=600,scrollbars=yes,left=35,top=35");
}
</script>
<!-- //2011년 05월 20일 팝업 추가// -->
[/code]
팝업 페이지
[code]
<html>
<head><title>조세현과 함께 하는 '사랑의 사진전'</title>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
//쿠키 생성 함수
function setCookie(name, value, expire) {
var expire_date = new Date(expire)
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expire_date.toGMTString();
}
//쿠키 소멸 함수
function clearCookie(name) {
var today = new Date()
//어제 날짜를 쿠키 소멸 날짜로 설정한다.
var expire_date = new Date(today.getTime() - 60*60*24*1000)
document.cookie = name + "= " + "; path=/; expires=" + expire_date.toGMTString()
}
//체크 상태에 따라 쿠키 생성과 소멸을 제어하는 함수
function controlCookie(elemnt) {
if (elemnt.checked) {
//체크 박스를 선택했을 경우 쿠키 생성 함수 호출
setCookie("member_gender","true","July 18, 2010 00:00:00")
//setTimeout("self.close()");
}
else {
//체크 박스를 해제했을 경우 쿠키 소멸 함수 호출
clearCookie("member_gender")
}
return
}
</script>
</head>
<body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'>
<table border='0' cellspacing='0' cellpadding='0'>
<tr><td>
<img src="./event_20110520.png" width="600px" border="0">
</td></tr>
<tr height='22'><td bgcolor='#EEEEEE'>
<center>
<input type="checkbox" name="closeEvent" onClick="controlCookie(this)">
하루동안 팝업창을 띄우지 않습니다.
<input type="button" value="닫기" onclick='self.close();'>
</center>
</td></tr>
</table>
</body>
</html>
[/code]
다음과 같은 소스로 셋팅했는데.. 팝업이 계속 뜨네요 한번 봐주세요~
메인 페이지
[code]
<!-- 2011년 05월 20일 팝업 추가 -->
<script language="javascript">
//쿠키값을 가져오는 함수
function getCookie(name) {
var from_idx = document.cookie.indexOf(name+'=');
if (from_idx != -1) {
from_idx += name.length + 1
to_idx = document.cookie.indexOf(';', from_idx)
if (to_idx == -1) {
to_idx = document.cookie.length
}
return unescape(document.cookie.substring(from_idx, to_idx))
}
}
//getCookie 함수를 호출하여 쿠키값을 가져온다.
var blnCookie = getCookie("member_gender");
//쿠키값이 true가 아닐 경우에만 새 창을 띄운다.
if ( !blnCookie ) {
window.open
("./event.html","_blink","width=620,height=600,scrollbars=yes,left=35,top=35");
}
</script>
<!-- //2011년 05월 20일 팝업 추가// -->
[/code]
팝업 페이지
[code]
<html>
<head><title>조세현과 함께 하는 '사랑의 사진전'</title>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
//쿠키 생성 함수
function setCookie(name, value, expire) {
var expire_date = new Date(expire)
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expire_date.toGMTString();
}
//쿠키 소멸 함수
function clearCookie(name) {
var today = new Date()
//어제 날짜를 쿠키 소멸 날짜로 설정한다.
var expire_date = new Date(today.getTime() - 60*60*24*1000)
document.cookie = name + "= " + "; path=/; expires=" + expire_date.toGMTString()
}
//체크 상태에 따라 쿠키 생성과 소멸을 제어하는 함수
function controlCookie(elemnt) {
if (elemnt.checked) {
//체크 박스를 선택했을 경우 쿠키 생성 함수 호출
setCookie("member_gender","true","July 18, 2010 00:00:00")
//setTimeout("self.close()");
}
else {
//체크 박스를 해제했을 경우 쿠키 소멸 함수 호출
clearCookie("member_gender")
}
return
}
</script>
</head>
<body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'>
<table border='0' cellspacing='0' cellpadding='0'>
<tr><td>
<img src="./event_20110520.png" width="600px" border="0">
</td></tr>
<tr height='22'><td bgcolor='#EEEEEE'>
<center>
<input type="checkbox" name="closeEvent" onClick="controlCookie(this)">
하루동안 팝업창을 띄우지 않습니다.
<input type="button" value="닫기" onclick='self.close();'>
</center>
</td></tr>
</table>
</body>
</html>
[/code]
댓글 2개
제가 사용하는 팝업창 띄우기 입니다.
1. index.html 파일 내용
<script language="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 openCookieWin() {
if ( getCookie( "gongji1" ) != "no" )
{
gongji1=window.open("popup.html",""," top=0,left=100,width=540,height=700,scrollbars=yes")
gongji1.opener = self;
//팝업창의 주소, 같은 도메인에 있어야 한다.
}
}
//-->
</script>
*** 중요사항 ***
< body 태그안에......... onload="openCookieWin()" 를 넣어줘야함 ~~~!
2. popup.html
<!------------------ 쿠키 필요한 부분 ----------------->
<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.checkClose.event.checked )
setCookie("gongji1", "no" , 1); // 1일 간 쿠키적용
// gongji1 <--- 쿠키 이름
self.close();
}
</script>
창닫기 부분
<form name="checkClose">
<input type="checkbox" name="event" onClick="closeWin()">
오늘하루 이 창을 띄우지 않음 <a href="#" onClick="closeWin()"> [닫기]</a>
</form>
1. index.html 파일 내용
<script language="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 openCookieWin() {
if ( getCookie( "gongji1" ) != "no" )
{
gongji1=window.open("popup.html",""," top=0,left=100,width=540,height=700,scrollbars=yes")
gongji1.opener = self;
//팝업창의 주소, 같은 도메인에 있어야 한다.
}
}
//-->
</script>
*** 중요사항 ***
< body 태그안에......... onload="openCookieWin()" 를 넣어줘야함 ~~~!
2. popup.html
<!------------------ 쿠키 필요한 부분 ----------------->
<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.checkClose.event.checked )
setCookie("gongji1", "no" , 1); // 1일 간 쿠키적용
// gongji1 <--- 쿠키 이름
self.close();
}
</script>
창닫기 부분
<form name="checkClose">
<input type="checkbox" name="event" onClick="closeWin()">
오늘하루 이 창을 띄우지 않음 <a href="#" onClick="closeWin()"> [닫기]</a>
</form>
게시글 목록
| 번호 | 제목 |
|---|---|
| 284438 | |
| 284437 | |
| 284435 | |
| 284430 | |
| 284420 | |
| 284417 | |
| 284409 | |
| 284401 | |
| 284399 | |
| 284397 | |
| 284380 | |
| 284378 | |
| 284371 | |
| 284370 | |
| 284366 | |
| 284364 | |
| 284360 | |
| 284357 | |
| 284355 | |
| 284354 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기