web blazonry web development scripts and tutorials Get best price on Prepaid Cheapest Smartphone
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       Resources   

Javascript Home


image scripts
  Image Load Order
  Mouse Overs
  SlideShow

JavaScript Resources
  Free JavaScript Books(new)
  Recommended Sites
  Bestselling Books

Bookmark and Share




JavaScript: How to Work With Cookies

Cookies: Putting It All Together & Summary (Part 5)

Our cookie tutorial used JavaScript and HTML forms to create and work with a cookie file. In actual use, you would call your cookie functions when your page is loaded.

Put the JavaScript cookie functions at the top of your file like in the previous pages of this tutorial. After your HTML BODY tag, call the relevant cookie function.

Saving a Cookie
Save your cookie with code that looks like this:

<script language="JavaScript"><!--
var exp = new Date();     //create new date object
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead

setCookie("myCookie","it is crunchy", exp);     //save the cookie

//-->
</script>

Retrieving the Cookie
Retrieve the cookie with code like this:

<script language="JavaScript"><!--
getCookie("myCookie");
//-->
</script>

For debugging, you can print out the cookie to your browser:

<script language="JavaScript"><!--
document.write(getCookie("myCookie"));
//-->
</script>

Deleting the Cookie
Delete the cookie with code like this:

<script language="JavaScript"><!--
delCookie("myCookie");
//-->
</script>

Summary of Using JavaScript to Save, Retrieve and Delete a Cookie

There you have it. This wasn’t the most spectacular example of using a cookie, but this is meant to get you started. Understand the basics of working with cookies and then you can build from here and use cookies in more sophisticated and innovative ways. Have fun with it and hope it helps.


Return to First Page of Cookie Tutorial

 

Related Links:

    Cookie Central -- a site devoted completely to information about cookies.

 

Newest Pages
Test Google Ads Ver. 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources
 
 

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.