352 Part (Business web site) III . Document Objects Reference var

352 Part III . Document Objects Reference var exp = new Date() var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000) exp.setTime(oneYearFromNow) Then convert the date to the accepted GMT string format: document.cookie = userName=Fred; expires= + exp.toGMTString() In the cookie file, the expiration date and time is stored as a numeric value (seconds) but, to set it, you need to supply the time in GMT format. You can delete a cookie before it expires by setting the named cookie s expiration date to a time and date earlier than the current time and date. The safest expiration parameter is expires=Thu, 01-Jan-70 00:00:01 GMT Omitting the expiration date signals the browser that this cookie is temporary. The browser never writes it to the cookie file and forgets it the next time you quit the browser. Path For client-side cookies, the default path setting (the current directory) is usually the best choice. You can, of course, create a duplicate copy of a cookie with a separate path (and domain) so that the same data is available to a document located in another area of your site (or the Web). Domain To help synchronize cookie data with a particular document (or group of documents), the browser matches the domain of the current document with the domain values of cookie entries in the cookie file. Therefore, if you were to display a list of all cookie data contained in a document.cookie property, you would get back all the name/value cookie pairs from the cookie file whose domain parameter matches that of the current document. Unless you expect the document to be replicated in another server within your domain, you can usually omit the domain parameter when saving a cookie. Default behavior automatically supplies the domain of the current document to the cookie file entry. Be aware that a domain setting must have at least two periods, such as .mcom.com .hotwired.com Or, you can write an entire URL to the domain, including the http://protocol. SECURE If you omit the SECUREparameter when saving a cookie, you imply that the cookie data is accessible to any document or CGI program from your site that meets the other domain- and path-matching properties. For client-side scripting of cookies, you should omit this parameter when saving a cookie. Retrieving cookie data Cookie data retrieved via JavaScript is contained in one string, including the whole name-data pair. Even though the cookie file stores other parameters for each cookie, you can retrieve only the name-data pairs via JavaScript. Moreover, when two or more (up to a maximum of 20) cookies meet the current domain criteria, document.cookie
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Leave a Reply