도메인 기반 쿠키를 생성하려면 쿠키에 도메인 및 경로 속성을 다음과 같이 설정하십시오. -
domain=.example.com
예
도메인 기반 쿠키를 만드는 방법을 배우기 위해 다음 코드를 실행할 수 있습니다. −
라이브 데모
<html>
<head>
<script>
<!--
function WriteCookie() {
if( document.myform.customer.value == "" ){
alert("Enter some value!");
return;
}
cookievalue= escape(document.myform.customer.value) + ";";
document.cookie = "name=" + cookievalue + ";
domain=.example.com;path=/";
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>
</head>
<body>
<form name = "myform" action = "">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onclick="WriteCookie();"/>
</form>
</body>
</html>