javascript, jquery

$.cookie / $.removeCookie - 쿠키 제어하기

디츠 2014. 10. 11. 22:58

* jquery.cookie.js

https://github.com/carhartl/jquery-cookie

jquery.cookie.js
다운로드

 

* request.html

<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>

<script>
$(function() {
	$.removeCookie('popup', {path:'/'}); // 쿠키삭제 경우
	if($.cookie("popup") == "ok") {
		// 쿠키가 있을때 처리내용
	} else {
		window.open('popup.html');
	}
});
</script>

* popup.html

<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>

<script>
$(document).ready(function() {
	$("#popup").click(function() {
		if($("#popup").is(":checked") == true) {
			$.cookie('popup','ok',{expires:1,path:'/',domain:'www.test.com',secure:false}); // 브라우저에 따라 안될경우 domain과 secure 부분 삭제
		}
	});
});
</script>

하루동안 창 열지않기 <input type="checkbox" id="popup" />