डोमेन-आधारित कुकी बनाने के लिए, अपनी कुकी पर डोमेन और पथ विशेषता सेट करें, जैसे -
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>