쿠키 적용으로 체크하면 다음부터는 뜨지 않는 창
인터넷정보2007. 10. 18. 13:44
새창뛰우는 창의헤드부분에 삽입.(본페이지)
<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('cook.html','_blink','width=225,height=250,scrollbars=no,toolbar=no,left=0,top=0');
}
</script>
---------여기까지------
새창에 들어갈 소스(cook.html)
<html>
<head>
<script language="javascript">
//쿠키 생성 함수
function setCookie(name, value, expire) {
var expire_date = new Date(expire)
document.cookie = name + "=" + escape(value) + "; 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 + "= " + "; 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>
<p>
<form>
<A onclick="javascript:document.all.closeEvent.checked=true;closeWin();window.opener.document.location.href='event.html';" href="#None">
<IMG src="event.gif" border=0>
</A>
<input type="checkbox" name="closeEvent" onClick="controlCookie(this)">다시는 이창 열지 않기
<input type="button" value="닫기" onclick='self.close();'><br>
</form>
</body>
</html>
-----여기까지
<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('cook.html','_blink','width=225,height=250,scrollbars=no,toolbar=no,left=0,top=0');
}
</script>
---------여기까지------
새창에 들어갈 소스(cook.html)
<html>
<head>
<script language="javascript">
//쿠키 생성 함수
function setCookie(name, value, expire) {
var expire_date = new Date(expire)
document.cookie = name + "=" + escape(value) + "; 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 + "= " + "; 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>
<p>
<form>
<A onclick="javascript:document.all.closeEvent.checked=true;closeWin();window.opener.document.location.href='event.html';" href="#None">
<IMG src="event.gif" border=0>
</A>
<input type="checkbox" name="closeEvent" onClick="controlCookie(this)">다시는 이창 열지 않기
<input type="button" value="닫기" onclick='self.close();'><br>
</form>
</body>
</html>
-----여기까지
'인터넷정보' 카테고리의 다른 글
프레임 나누어진 페이지 늘리기 - 확장시키기 (0) | 2007.10.18 |
---|---|
프레임 나타내기(히든프레임)와 숨기기 (0) | 2007.10.18 |
셀렉트 박스 새창과 현재창을 라이오 버튼으로 제어 (0) | 2007.10.18 |
셀렉트를 이용해서 이미지 선택 나타내기 (0) | 2007.10.18 |
이미지 슬라이드 (0) | 2007.10.18 |
이미지에 섬광 효과 주기 (0) | 2007.10.18 |
자바스크립트와 테이터베이스 연동 (0) | 2007.10.18 |
TextField의 Align - 텍스트 정렬 및 콤마 찍기 (0) | 2007.10.18 |
텍스트 애니메이션 (0) | 2007.10.18 |
웹페이지 대화상자 (부모창 위에 새창이 항상 최상위에 존재) (0) | 2007.10.18 |
스크립트로 쿠키 굽기
인터넷정보2007. 10. 12. 12:14
// 쿠키의 값을 가져오는 함수입니다. // GetCookie(쿠키이름); function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal! (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } // 쿠키를 굽는 함수입니다. // php 의 setcookie() 함수와 동일하게 사용하면 됩니다. // SetCookie (쿠키이름,값,보관시간,디렉토리,도메인,....); function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } // 쿠키를 지우는 함수 입니다. // DeleteCookie (쿠키이름); function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); // This cookie is history var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); } //GetCookie() 에서 사용하는 함수 따로 쓸일은 없습니다.:) function getCookieVal! (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); }
'인터넷정보' 카테고리의 다른 글
마우스 커스 이동,클릭만으로 배경색상을 바꾸어보자 (0) | 2007.10.12 |
---|---|
창을 열면 인사하는 간단한 스크립트 - 프롬프트 (0) | 2007.10.12 |
자바스크립트로 변수처리하기! (0) | 2007.10.12 |
마우스 오버시 그림이 선명해지는 스크립트 (0) | 2007.10.12 |
페이지마다 타이틀 변경하기 (0) | 2007.10.12 |
블라인드 효과 스크립트 (0) | 2007.10.12 |
사용자 해상도 알아내는 스크립트 (0) | 2007.10.12 |
링크 클릭시 상단으로 이동하지 않게.. (0) | 2007.10.12 |
PHP 구구단 만들기 (0) | 2007.10.12 |
PHP 원의 넓이 구하기 (0) | 2007.10.12 |
현재 페이지 쿠키 알아내기
인터넷정보2007. 10. 10. 14:20
javascript:alert(decodeURIComponent(document.cookie.toString()).replace(/;/g,';\n'));
javascript:alert(document.cookie.toString()).replace(/;/g,';\n');
인코딩된거 디코딩해주고, 줄바꿈해줌
'인터넷정보' 카테고리의 다른 글
라디오 선택된 값 가져오기 (0) | 2007.10.11 |
---|---|
input text용 updown 버튼 (0) | 2007.10.11 |
입력 글자바이트 제한 textarea,textbox용 (0) | 2007.10.11 |
mysql 기본명령어 (0) | 2007.10.11 |
윈도우용 주요 프로세스 목록이 있는 사이트 (0) | 2007.10.11 |
바이러스 백신 소프트웨어 공급업체 목록 (0) | 2007.10.10 |
간단한 중요 DB정보 보호방법 (0) | 2007.10.10 |
SSL관련 개인키, CSR 만드는 방법 (0) | 2007.10.10 |
IE flash 패치용 - 이올라스, 플래시 테두리 (0) | 2007.10.10 |
file에 스킨 입히기 - 첨부파일 (0) | 2007.10.10 |