KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Best books about Javasript

Javascript set cookie

What is Cookie? Cookie is a piece of information browsers put on the client's PC. Cookie include 6 part, which are name,value,expire date, path, domain and security. A cookie always has its name and value.(Otherwise, you don't need set up a cookie.) The other 4 parts are optional.

Expire date is used to set cookie lifespan. If a cookie (like document.cookie ="username=bill;" ) without expire date, this cookie will be gone when the user closes his brower.

Path sets up restriction for sub-directories accession. For example, if www.yourwebsit.com/bill/tools sets a cookie, subdirectory www.yourwebsit.com/bill/checkout could not read that cookie unless you set cookie like

document.cookie="username=Bill;path="/bill;";

This way, all subdirectories under /bill (eg,/tools and /checkout) can share their cookies.

If set "path=/;", the cookie will be available to all directories on the domain where it is set from.If the web site is just one of that domain, such as a free hosting usually have a lot of uers sharing same directory, the other user also could access the cookie you set.

Domain: By default, collies are only accessable to pages in the domain they are set from. But if a site have subdomains, like forum.yourwebsite.com and photos.yourwebsite.com, a cookie set by a domain is not available to the other one. In order to share cookie cross subdomain, cookies could set "domain=yourwebsite.com".

Security: By default, the value of security is false.It means a cookie is always send back to the pages. If the value is true, it requires a server with Secure sockets layer(SSL).

In order to use the example in this page, your web browser should accept cookies.

How to do set cookies? Copy the following scripts to <head></head> section.

            

Click here to see how to get cookie.

 

 

 

Best books about ASP & ASP.Net from Amazon
JavaScript Bible, Fifth Edition (Paperback) JavaScript & DHTML Cookbook (Paperback) JavaScript: The Definitive Guide (Paperback) Beginning JavaScript Second Edition (Paperback) JavaScript: The Complete Reference, Second Edition (Paperback)

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer