Javascript cookie string

We can set a cookie by setting document.cookie to a cookie string.
 The following code will set a cookie with the UserName set as Paul,
 and an expiration date of 28 December 2010.

<html>
<head>
<script language=JavaScript>
   document.cookie = "UserName=Paul;expires=Tue, 28 Dec 2010 00:00:00;";
</script>
</head>
<body>
<p>This page just created a cookie</p>
</body>
</html>

Save the page as FreshBakedCookie.htm. We'll see how the code works as we
 discuss the parts of a cookie string, but first let's see what happens
 when a cookie is created.

In this section we'll see how to look at the cookies that are already stored by IE on our computer. We'll then load the cookie-creating page we just created with the preceding code to see what effect this has.

First we need to open IE. I'm using IE 6, so if you're using IE 4 or 5 you will find the screenshots and menus in slightly different places.

Before we view the cookies, we'll first clear the temporary Internet file folder for the browser because this will make it easier to view the cookies that our browser has stored. In IE, select Internet Options from the Tools menu,




Related Posts:
  • JavaScript Refresh Page you refresh the page using document.location.reload(). You can add the true keyword to force the reloaded page to come from the server (instead of cache). Alternatively, you can use the false keyword to reload the page from … Read More
  • Remote JavaScript The primary reason is that the round trip time required to submit a form and then download the response is often inconvenient. The user experience is much improved if, instead of clicking a Submit button and watching the … Read More
  • JavaScript Dynamic Links and Menus Many sites use JavaScript to create links to other website pages. Here is some examplecode with different link types that you may want to avoid: <HTML><head><title>Link Examples ~ Things to stay away from&l… Read More
  • Javascript Recursion Recursion is when a function calls itself. This is often useful in mathematics,such as fi nding the nth number in the Fibonacci series (1, 2, 3, 5,8, 13, 21…).function fi bonacci(n) {if ( n < 2 ) {return 1;} else {return … Read More
  • Javascript The + Operator The binary + operator adds numeric operands or concatenates string operands: 1 + 2 // => 3"hello" + " " + "there" // => "hello there""1" + "2" // => "12" When the values of both operands are numbers, or are both str… Read More
  • The try-catch Statement JavaScript provides a try-catch statement that is capable of intercepting thrown errors before they are handled by the browser. The code that might cause an error comes in the try block and code that handles the error goes i… Read More
  • Embedding Content for Plug-Ins Although never officially a part of any HTML specification, the <<embed>> tag is most often used to include embedded objects for Netscape and Internet Explorer. A Macromedia Flash file might be embedded as fo… Read More
  • Javascript Image Objects Properties of Image Objects Property Description align Indicates the alignment of the image, usually “left” or “right.” alt The alternative text rendering for the image as set by the alt attribu… Read More
  • Javascript Math object The Math object holds a set of constants and methods enabling more complex mathematical operations than the basic arithmetic operators var root = Math.sqrt(10); Constants Provided by the Math Object Property … Read More
  • Creating Elements, Attributes, and Objects An important benefit of dynamic content is the ability to create new content from freshly received data. This is necessary in dynamic menu creation, navigation, breadcrumbs, and web services, among other applications. Ajax… Read More
  • JavaScript Form Validation  JavaScript Form Validation. JavaScript can be used to validate data in HTML forms <script type="text/javascript"> function validate_all()     {     var frmReg=document.manageadmin… Read More
  • JavaScript and XML To demonstrate JavaScript, XML, and the DOM in action, let’s use Internet Explorer 5.5 or better to load an XML document containing our employee directory and see if we can manipulate it. First, to load in the document w… Read More
  • Expression Statements Assignment statements are one major category ofexpression statements.  For example: greeting = "Hello " + name;i *= 3; The increment and decrement operators, ++ and --, are relatedto assignment statements. These have … Read More
  • Function Call Spacing Almost universally, the recommended style for function calls is to have no space between the function name and the opening parenthesis, which is done to differentiate it from a block statement. For example: // Good doSom… Read More
  • JavaScript Object Literals Object literals are a popular way to create new objects with a specific set of properties, as opposed to explicitly creating a new instance of Object and then adding properties. For example, this pattern is rarely used: … Read More