|
Cookies are little JavaScript programs that
you can use to store information about visitors to your site.
The JavaScript leaves a cookie on a visitor's computer; when
a visitor revisits your site, you can read the information
and act on it. Cookies are not secret passageways into a visitor's
computer, but rather a bookmark to identify where you and
the visitor were in your adventure together. Creating a cookie
is actually a bit of a cooperative venture wherein the visitor
answers prompts on the page and you save the information in
a cookie. Two main types of cookies are:
|
|
Session
cookies, which endure only as long as visitor is at a page. |
|
|
Persistent
cookies, which endure until the expiration date that you set. |
Let us say, you want to keep some information
about a visitor's browsing session, such as the pages browsed
or the products purchased. You can do so using session cookies.
The JavaScript not only records the visitor's session information,
but also sends a message to the visitor when he or she arrives at and exits your site.
Syntax :
<HTML> <HEAD>
<TITLE> Cookies Form </TITLE>
Cookies Bearing Document
</HEAD> <BODY>
</BODY> </HTML>
Example :
<HTML>
<HEAD>
<TITLE> Cookies Form</TITLE>
<SCRIPT>
function homeMadeCookies
( ) {
var
gotHere = newDate( );
document.cookies
= gotHere.toLocaleString(
); }
function fareWell(
) {
var
timedVisit = newDate( );
var
tempTime = timedVisit.toLocalString( );
alert("You
got here at :" +document.cookies
+ "and now it's :"
+ tempTime); }
</SCRIPT>
</HEAD>
<BODY onLoad="homeMadeCookies( )" unLoad="fareWell(
)">
</BODY>
</HTML>
You can also store information in cookies
for a period of time. You use persistent cookies when you
want to store information to use in the future. For example,
if a visitor fills out a form that includes his or her name
and other personal information, you'd want to keep that information
and use it when the visitor visits in the future.
Here are some facts you should know about persistence cookies:
|
|
A browser retains a limited
number of cookies. Netscape Navigator retains 300 cookies.
Older cookies are discarded to make room for new ones. |
|
|
A cookie cannot be more than 4Kb. |
|
|
You can have only 20 cookies
per domain. If you're working from a large ISP, you might
not be able to set cookies for all visitors. |
These restrictions may not seem limiting
at first, but they become so when the demand for feedback increases.
Unlike session cookies, persistent cookies
need an expiration date. After the cookie expires, a former
visitor is treated as a new visitor.
Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.
|
|