Untitled Document



 Introduction to HTML
 Structure of HTML
 Creating First HTML  Document
 Building Your HTML  Document
 Tables
 Frames
 Including Images into  Document
 Including Multimedia
 Developing HTML  FORMS
 Using Style Sheet
 Understanding URLs
 Using JavaScript
 Introducing JavaScript
   Using JavaScript
 Introducing to  JavaScript
   What is JavaScript?
 Why should you use  Java Script?
 Structure of a  JavaScript
   Syntax of JavaScript
 JavaScript
 Statements
 
 Statements
 Blocks
 
 Blocks
 Comments
 
   Comments
 Single-Line  Comments
 Multiline Comments
 Data
 
   Data
   Strings
   Numbers
   Boolean
 Null
 Expressions
 
   Expressions
   Numeric Expressions
 Logical Expressions
 Variables
 
   Variables
 Defining and Naming  Variables
 Changing the Value  of a Variable
 Functions
 
   Functions
   Built-in Functions
 User-Defined  Functions
 Returning Values  from Function
 Flow Control
 
   Flow Control
   If and if ....else
   If Statement
   If...else Statement
   IF Statement
   Looping Statements
   For Loops
   While Loops
   WHILE Statement
   Switch Statement
   Break Statement
 Continue Statement
 Objects
 
   Objects
   Methods
   Properties
   Built-in Objects
 User-defined Objects
 Arrays
 
 Arrays
 Event Handlers
 
   Event Handlers
 onMouseOver,  onMouseOut Events
 onClick, onChange  Events Handlers
 Using the onSubmit  Event Handler
 Introduction to Cookies
 
 Introduction to  Cookies
   Sessions Cookies
 Persistent Cookies
 Using Java

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.




  Using JavaScript > Introduction to Cookies

  Introduction to Cookies

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.

  Sessions Cookies

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>
// We are trying to set the document cookies to the local time and date
< !--

function homeMadeCookies ( ) {
             var gotHere = newDate( );
             document.cookies = gotHere.toLocaleString( ); }
// - ->
/* Now we write another function which will display a message when the visitor leaves. */
<! - -

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( )">
/* The onLoad event handler starts the function called homeMadeCookies, which creates and place a value into the variable gotHere. From that information, the next line converts the GMT time and stores that in document.cookies. */
// The unLoad event will display time-in and time-out.

</BODY>
</HTML>

  Persistent Cookies

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.

Back Next


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.




17, Vadsarvala Nivas, 65-A, J. Nehru Road, Mulund (W), Mumbai - 400 080 INDIA
Tel : 91-22-21645588, 91-22-21640585 Fax : 91-22-21641545
Email : ionline@vsnl.com
© Image Online 2001-2003