HTML and CSS Reference
In-Depth Information
Path. The path is used to specify where the cookie is valid for a particular server. Set-
ting a path for the cookie allows other pages from the same domain to share a cookie.
FORMAT
; path=pathname
EXAMPLE
; path=/home
Secure. If a cookie is secure, it must be sent over a secure communication channel
(HTTPS server).
FORMAT
; secure
16.2 Creating a Cookie with JavaScript
In the following examples, we will create a cookie, view the cookie, and then destroy it.
It is important to note when you are setting cookies that they are stored in the browser's
memory and not written to the hard drive until you exit the browser.
16.2.1 The Cookie Object
The cookie is stored by JavaScript as a document object for both reading and writing
cookie data. Cookies are made by assigning attributes to the cookie property. When you
start your browser, if there are cookies, they pertain to the current document. The doc-
ument.cookie property contains a string of name=value pairs representing the names of
all the cookies and their corresponding values, such as a session ID number or a user ID.
All the other attributes set for the cookie, such as expiration date, path, and secure, are
not visible. In a JavaScript program, if you execute the statement shown in Figure 16.5,
you will see all the cookies set for this page.
Figure 16.5 Using alert(document.cookie);
 
 
 
Search WWH ::




Custom Search