किसी विशिष्ट पेज के लिए कुकीज़ सेट करने के लिए, आपको "window.location.pathname" प्रॉपर्टी का उपयोग करने की आवश्यकता है। यह प्रॉपर्टी वर्तमान पेज का पथ और फ़ाइल नाम लौटाती है।
उदाहरण
किसी विशिष्ट पेज के लिए कुकीज़ लागू करने के लिए निम्न कोड चलाकर देखें
लाइव डेमो
<html> <head> <script> <!-- function WriteCookie() { if( document.myform.customer.value == "" ) { alert("Enter some value!"); return; } cookievalue= escape(document.myform.customer.value) + ";"; var myPath = window.location.pathname; document.cookie="name=" + cookievalue + ";path=myPath"; 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>