Cookies and JavaScript - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Cookies and JavaScript

Description:

How to make your page really cook! Problem. Can my page 'remember' things? ... How do we query Cookie file? Need to reference the Cookie variable in Java or ... – PowerPoint PPT presentation

Number of Views:1225
Avg rating:3.0/5.0
Slides: 16
Provided by: norman5
Category:

less

Transcript and Presenter's Notes

Title: Cookies and JavaScript


1
Cookies and JavaScript
  • How to make your page really cook!

2
Problem Can my page remember things?
  • The WEB server has no way of tracking whether or
    not it has seen you before, since each request is
    independent of previous requests. It has no way
    of remembering that you were there.

3
Cookies
  • A COOKY is a file that resides on your hard drive
    and can be updated via HTML and queried via Java
    or Javascript
  • This allows your web site to store information
    about users in their cookie files, rather than
    devoting server storage to it.
  • For example, what happens if you store your
    homepage at NETSCAPE?

4
NETSCAPE HOME PAGES
  • Netscape allows user to build and store their own
    customized home pages.
  • Actually, all of the changeable material is not
    stored at NETSCAPE, but is just stored in the
    users cookie file.
  • A Javascript program is downloaded to the users
    and then dynamically generates their home page.
    The user can save it if they wish.

5
LOGIC
  • Javascript program checks to see if a homepage
    is already stored in your cookie file
  • If not, it queries the user and lets them choose
    different layouts and content.
  • All of this is stored back in their cookie file.
  • The next time they go to netscape.com/custom
    their homepage is displayed.

6
The trick ...
  • All that is ever at Netscape is a Javascript
    program
  • Every user gets a different page when they point
    to http//www.netscape.com/custom
  • Netscape can support an infinite number of users
    with one homepage.

7
Hmmm What are the limitations
  • Cookie file is on a machine, so all users from
    the same machine get the same homepage (wont
    work in the labs)
  • How do we fix this?
  • Name the homepages? that allows multiple users on
    the same machine but
  • Store cookie file on H drive? maybe..

8
Look at the source at Netscape
9
How do we use Cookie files in Marketing?
  • Store customer characteristics in cookie file
  • Adapt site behavior based on these
    characteristics
  • Update Cookie file with new info as customer
    changes behavior

10
How do we query Cookie file?
  • Need to reference the Cookie variable in Java or
    Javascript
  • Code will dynamically decide what to display
    based on Cookie values
  • For instance, query a database back on server for
    all products that match cookie specs

11
  • function getCookie(name)
  • var cookie " " document.cookie
  • var search " " name ""
  • var setStr null
  • var offset 0
  • var end 0
  • if (cookie.length gt 0)
  • offset cookie.indexOf(search)
  • if (offset ! -1)
  • offset search.length
  • end cookie.indexOf("",
    offset)
  • if (end -1)
  • end
    cookie.length
  • setStr
    unescape(cookie.substring(offset,
  • end))
  • return(setStr)

12
Reading Cookie with GetCookie
  • The results are directed into variables in your
    routine
  • To retrieve the value of cookie foo,
  • Insert the getcookie function in your code and
    then the following Javascript line will get the
    value of the cookie..
  • myVar GetCookie("foo")

13
Other Techniques
  • JAVA Applet
  • Dynamic HTML
  • CGI program with server data base

14
Find some examples
  • Javascript - Netscape home page construction kit
  • JAVA?
  • CGI (most sites)

15
Conclusion
  • Cookies, CGI and Javascript can be used together
    to maintain persistent information on the
    clients computer.
  • Information could be list of entertainment
    channels, their userid and password to the site
    etc.
  • Check out the cookies on your home computer.
Write a Comment
User Comments (0)
About PowerShow.com