ể tạo ra một cookie và lưu trữ nó trên ổ cứng của người dùng, tất cả những gì bạn cần làm là thiết lập thuộc tính bằng một chuỗi có chứa các tên yêu cầu / cặp giá trị và bất kỳ, các thuộc tính tập tin cookie tùy chọn dấu chấm phẩy phân cách, như thể hiện trong đoạn mã sau đây | Chapter 6 That s How the Cookie Crumbles 133 To create a cookie and store it on the user s hard drive all you need to do is set the property equal to a string containing the required name value pair and any optional semicolon-delimited cookie attributes as shown in the following code snippet taken from Listing 6-1 which appears later in this chapter name escape value expires null expires path null path path domain null domain domain secure true secure The cryptic odd-looking syntax condition something somethingElse is JavaScript shorthand for if this condition is true then add something. Otherwise add somethingElse. For example here s how the JavaScript interpreter sees the JavaScript phrase expires null expires It thinks to itself If the value for expires is null add to the d property. Otherwise add the string expires someGMTFormattedDate to the property. You can find out more about the conditional operator in Chapter 3. Accessing a cookie You can set attributes for a cookie by using JavaScript specifically the expires path domain and secure attributes as I describe in the section Setting a cookie but you can t access those attributes by using JavaScript. In contrast you can access a cookie s value. This seemingly odd state of affairs being able to set attributes that you can t retrieve actually makes sense when you think about it. All these attributes are security-related and preventing them from being altered helps maintain cookies integrity and safety. After you give out your cookies only the Web browser is privy to cookie attributes. To access a cookie s value you query the cookie property associated with the d ocument object. You see how to set the cookie property in Setting a cookie earlier in this chapter. 134 Part II Creating Dynamic Web Pages Check out the following JavaScript code snippet var endstr offset . return unescape .