쿠키를 생성하는 동안 "경로" 매개변수를 사용하십시오. 디렉토리 또는 웹 페이지의 경로는 쿠키를 설정합니다. 현재 페이지에서 쿠키를 검색하려면 공백일 수 있습니다. 기본적으로 쿠키는 현재 페이지에 속합니다.
예시
현재 페이지의 모든 쿠키를 나열하려면 다음 코드를 시도하십시오 -
실시간 데모
<html>
<head>
<script>
function ReadCookie() {
var allcookies = document.cookie;
document.write ("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++) {
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
document.write ("Key is : " + name + " and Value is : " + value);
}
}
</script>
</head>
<body>
<form name="myform" action="">
<p> click the following button and see the result:</p>
<input type="button" value="Get Cookie" onclick="ReadCookie()"/>
</form>
</body>
</html>