<<Back to Article

Isolate Cookies

/skill level/
/viewed/
0 Times

Here's some (slightly simplified) code taken from Thau's Advanced JavaScript Tutorial that allows you to isolate a specific cookie.



function WM_readCookie(name) {


if (document.cookie == '') {


// there's no cookie, so go no further


return false;


} else {


// there is a cookie


var firstChar, lastChar;


var theBigCookie = document.cookie;


firstChar = theBigCookie.indexOf(name);


// find the start of 'name'


if(firstChar != -1) {


// if you found the cookie


firstChar += name.length + 1;


// skip 'name' and '='


lastChar = theBigCookie.indexOf(';', firstChar);


// Find the end of the value string (i.e. the next ';').


if(lastChar == -1) lastChar = theBigCookie.length;


return unescape(theBigCookie.substring(firstChar, lastChar));


} else {


// If there was no cookie of that name, return false.


return false;


}


}

}


// WM_readCookie

Code and Explanation

The Tags



HTML - This tells the browser this is a HTML document. Put the start tag, <HTML>, at the beginning of your document and the end tag, </HTML>, at the bottom of your document.

  <HTML> Put your whole document in here. </HTML>

TITLE - Every page should have a title. The title will appear as the window title.

  <TITLE>My Web Site</TITLE>

BODY - This lets you specify the colour of the background or lets you put a graphic in the background. Colours have to be specified in hexadecimal format, which is kind of confusing, but we included some samples below. To change the background colour use “bgcolor” to change the colour of the text use “text”. At the end of your page, include the closing </BODY> tag.

  <BODY bgcolor="ffffff" text="3344cc">
  <BODY background="pretty_graphic.gif">
P - Indicates a paragraph. You should use both the opening

tag and the closing

tag.

This is the beginning of a new paragraph.

And this is the next paragraph.

FONT - Controls the size, colour, and typeface of the text. Size is controlled by increasing or decreasing the text’s normal size. Size="+2" would increase the font by two and size="-2" would decrease it by two. “Face” is used to change to a different font, but be warned that you, or the person reading your page, will have to have the font installed for it to display properly.

  Text goes here
  Text
  Text

B, I, U - To make text bold, italics, or underlined.

  Bold me, please
  Aren’t italics nice
  Underline is nice too

IMG - Used to include a graphic on your page. The browser will look for a graphic in the same directory (or folder) as your web page file is in, so make sure that’s where your graphics are.

    Although it isn’t necessary, it is a good idea to include the width and height (in pixels) of the graphic. If you don’t know the size, leave it out altogether. The IMG tag also allows you to add a border to the graphic using “border”. For a border one pixel thick, use border="1".
  The IMG tag doesn’t have a close tag.
  <IMG width="100" height="25" SRC="my_graphic.gif">
  <IMG border="1" SRC="my_photo.jpeg">

A HREF - This will make a “hot” link to other pages, sites, or email. You can also make a graphic “clickable” by embedding an <IMG> between the start and end tags.

  <A HREF="http://myspace.com/steven1steve">YES Mag</A>
  <A HREF="otherpage.html">My other page</A>
  <A HREF="intruda333@aim.com">Send us email</A>
  <A HREF="http://www.yesmag.ca"><IMG SRC="yesmag_logo.gif"></A>


Bold text

  • This page was last modified 01:52, 24 October 2008.
Edit this article
Reddit Digg