เพื่อตั้งค่า cookies สำหรับหลายหน้า คุณต้องตั้งค่า path เป็น:
;path=/
ตัวอย่าง
ข้างต้นจะทำให้ cookies ของคุณกลายเป็น site cookie คุณสามารถลองรันโค้ดต่อไปนี้เพื่อตั้งค่า cookies สำหรับหลายหน้า:
Live Demo
<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 + "; 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>