[ javascript ] 쿠키 셋팅 추출 삭제 > javascript&jQuery

본문 바로가기
사이트 내 전체검색

javascript&jQuery

[ javascript ] 쿠키 셋팅 추출 삭제

페이지 정보

작성자 웹지기 댓글 0건 조회 1,688회 작성일 18-10-01 02:56

본문

[code]

<script>

//쿠키 불러내기

function getCookie( cookieName ) 

{

var search = cookieName + "=";

var cookie = document.cookie;

// 현재 쿠키가 존재할 경우

if( cookie.length > 0 ){

// 해당 쿠키명이 존재하는지 검색한 후 존재하면 위치를 리턴.

startIndex = cookie.indexOf( cookieName );

// 만약 존재한다면

if( startIndex != -1 ){

// 값을 얻어내기 위해 시작 인덱스 조절

startIndex += cookieName.length;

// 값을 얻어내기 위해 종료 인덱스 추출

endIndex = cookie.indexOf( ";", startIndex );

// 만약 종료 인덱스를 못찾게 되면 쿠키 전체길이로 설정

if( endIndex == -1) endIndex = cookie.length;

// 쿠키값을 추출하여 리턴

return unescape( cookie.substring( startIndex + 1, endIndex ) );

}else{

// 쿠키 내에 해당 쿠키가 존재하지 않을 경우

return false;

}

}else{

  // 쿠키 자체가 없을 경우

  return false;

    }

}

 

function setCookie( cookieName, cookieValue, expireDate ) 

{

var today = new Date();

//today.setDate( today.getDate() + parseInt( expireDate ) );

//today.setDate( today.getMinutes() + parseInt( expireDate ) );

today.setDate( today.getSeconds() + parseInt( expireDate ) );

//document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + today.toGMTString() + ";";

document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + today.toGMTString() + " ;";

}


function deleteCookie( cookieName )

{

var expireDate = new Date();

//어제 날짜를 쿠키 소멸 날짜로 설정한다.

expireDate.setDate( expireDate.getDate() - 1 );

document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";

}


function setMyCookie() 

{

setCookie( form.setName.value, form.setValue.value, form.expire.value );

viewCookie(); // 전체 쿠키 출력 갱신

}


function getMyCookie()

{

alert( "쿠키 값 : " + getCookie( form.getName.value ) );

}


function deleteMyCookie() 

{

deleteCookie( form.deleteName.value );

alert("쿠키가 삭제되었습니다.");

viewCookie();

}


function viewCookie()

{

if( document.cookie.length > 0 )

cookieOut.innerText = document.cookie;

else

cookieOut.innerText = "저장된 쿠키가 없습니다.";

}

</script>

<body onload = "viewCookie()">

<form name = "form">

쿠키 설정<br>

쿠키명 : <input type = "text" name = "setName"><br>

쿠키값 : <input type = "text" name = "setValue"><br>

기한 : <input type = "text" name = "expire"><br>

<input type = "button" onClick = "setMyCookie()" value = "쿠키설정"><br><br>

쿠키 확인<br>

쿠키명 : <input type = "text" name = "getName"><br>

<input type = "button" onClick = "getMyCookie()" value = "쿠키확인"><br><br>

쿠키 삭제<br>

쿠키명 : <input type = "text" name = "deleteName"><br>

<input type = "button" onClick = "deleteMyCookie()" value = "쿠키삭제"><br><br>

전체쿠키<br>

<div id = "cookieOut"></div>

</form>

</body>

[/code]

추천0 비추천0

댓글목록

등록된 댓글이 없습니다.

Total 63건 4 페이지
  • 18 [ jquery ] 강좌 및 동영상
  • jQuery 시리즈 강좌 리스트[jQuery강좌] 1. 웹 개발자를 위한 jQuery 기본이해[jQuery강좌] 2. jQuery를 이용한 HTML DOM 접근 - 기본 셀렉터 (1)[jQuery강좌] 3. jQuery를 이용한 HTML DOM 접근 - 기본 셀렉터 (2)[jQuery강좌] 4. jQuery Selector - 속성(Attribute)[jQuery강좌] 5. jQuery Selector - DOM 계층(Hierarchy)을 이용한 요소 접근 (1)[jQuery강좌] 6. jQuer...
  • 웹지기 09-27 1898 0 0 댓글 0
  • 15 [ jquery ] jquery 기본 명령어
  • [code].appendTo() ==&gt; 1.새로운 요소를 타겟(target)에 해당하는 요소 마지막에 추가합니다. $("span").appendTo("#foo");.append() ==&gt; 2.last() ==&gt; 7.siblings() ==&gt; 8.prevAl!l() ==&gt; 11.prev() ==&gt; 12.prevUntil() ==&gt; 13.parentsUntil() ...
  • 웹지기 09-30 2670 0 0 댓글 0
  • 14 [ javascript ] 현재시간 실시간으로 보기
  • [code] &lt;script type="text/javascript"&gt;function printTime() { var clock = document.getElementById("clock"); var now = new Date(); var ampm; if (now.getHours() &gt;= 12) { ampm = "PM"; } else { ampm = ...
  • 웹지기 09-28 2600 0 0 댓글 0
  • 열람중 [ javascript ] 쿠키 셋팅 추출 삭제
  • [code]&lt;script&gt;//쿠키 불러내기function getCookie( cookieName ){ var search = cookieName + "="; var cookie = document.cookie; // 현재 쿠키가 존재할 경우 if( cookie.length &gt; 0 ){ // 해당 쿠키명이 존재하는지 검색한 후 존재하면 위치를 리턴. startIndex = cookie.indexOf( cookieName ); // 만...
  • 웹지기 10-01 1689 0 0 댓글 0
  • 8 [ jquery ] 소숫점 콤마 동시사용 플러그인
  • jQuery Number Plugin By Sam Sehnert, Custom D 2015 This is a jQuery plugin which allows developers to easily format numbers for display use. Allows users to replace numbers inline in a document, or return a formatted number for other uses. Requires jQuery 1.6 or greater. ...
  • 웹지기 09-07 4836 0 0 댓글 0
  • 6 [ javascript ] 논리 연산자 활용 (삼항연산자의 역할)
  • var day = day_time || day_day || 31; 위의 내용을 풀이하면 day 변수에 값을 넣을 때 day_time 값이 존재하면 day_time 값을 day에 대입한다. day_time값이 없고 day_day에 값이 존재하면 day_day 값을 day에 대입한다. day_time 값이 없고 day_day 값도 없다면 31이라는 값을 day에 대입한다. 이는 삼항 연산자 처럼 사용할 수 있어서 편리하다. functio num(a) { b = a || 29; } 이...
  • 웹지기 11-19 1036 0 0 댓글 0
  • 5 [ javascript ] 동일 연산자와 일치 연산자
  • 동일 연산자 ( == ) 값을 비교해 보자면 null == undefined // -&gt; true 1 == "1" // -&gt; true true == 1 // -&gt; true "0xff" == 255 // -&gt; true (new String("a")) == "a" // -&gt; true (new Number(2)) == 2 // -&gt; tr...
  • 웹지기 11-19 1062 0 0 댓글 0
  • 4 [ javascript ] 변수 명명 규칙, 표기법
  • 캐멀 표기법(로어 캐멀 표기법) newName createLifeGame 파스칼 표기법(어퍼 캐멀 표기법) NewName CreateLifeGame 밑줄 표기법(스네이크 표기법) new_name create_life_game 변수 이름을 지을 때 일반적으로 사용하는 표기법 - 캐멀 표기법, 밑줄표기법으로 변수의 의미를 파악할 수 있게 명명 - 기본적으로 영어로 사용 - 루프 카운터 변수는 i, j, k 등을 사용 -...
  • 웹지기 06-04 2484 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
6,514
어제
29,471
최대
33,828
전체
8,505,055

그누보드5
Copyright © funyphp.com. All rights reserved.