0% found this document useful (0 votes)
20 views17 pages

Lecture 9

The document explains the concept of cookies in web development, detailing their function as small text files that store user data on a visitor's computer. It covers how cookies are created, stored, and transmitted between browsers and servers, as well as their applications in tracking user sessions and preferences. Additionally, it highlights the role of JavaScript in managing cookies and enhancing user experience through dynamic web interfaces.

Uploaded by

darunraj365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views17 pages

Lecture 9

The document explains the concept of cookies in web development, detailing their function as small text files that store user data on a visitor's computer. It covers how cookies are created, stored, and transmitted between browsers and servers, as well as their applications in tracking user sessions and preferences. Additionally, it highlights the role of JavaScript in managing cookies and enhancing user experience through dynamic web interfaces.

Uploaded by

darunraj365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

 Introduction

 Types
 Create and Store a Cookie
 Applications of JS
 JS Object model
A cookie is a variable that is stored on the
visitor's computer. Each time the same
computer requests a page with a browser, it
will send the cookie too. With JavaScript,
you can both create and retrieve cookie
values.
 Name cookie
 Password cookie
 Date cookie
• HTTP cookies (also referred to as Web
cookies, tracking cookies, or cookies) are
small text files containing a user's settings
and other data used by websites, and are
stored on the user's computer. They are
transmitted as parcels of text sent by a
server to a Web client (usually a browser)
and then sent back unchanged by client each
time it accesses that server. HTTP cookies
are used for authenticating, session tracking
(state maintenance), and maintaining
specific information about users
• Cookies are not computer programs that run
on the browsing computer
• The pieces of information are stored as name-
value pairs.
• For example, a Web site might generate a unique
ID number for each visitor and store the ID
number on each user's machine using a cookie
file.
• The most common place for them to reside is in
a directory called c:\windows\cookies.
• For example, on visiting goto.com, the site
places a cookie on the machine. The cookie file
for goto.com contains the following information:
• UserID A9A3BECE0563982D www.goto.com
/
 The data moves in the following manner:
 If you type the URL of a Web site into your browser, your
browser sends a request to the Web site
 When the browser does this, it will look on your machine for a
cookie file that Amazon has set. If it finds an Amazon cookie
file, your browser will send all of the name-value pairs in the
file to Amazon's server along with the URL
 Web server receives the cookie data and the request for a
page. If name-value pairs are received, it can use them.
 If no name-value pairs are received, it knows that you have not
visited before. The server creates a new ID for you in database
and then sends name-value pairs to your machine in the header
for the Web page it sends. Your machine stores the name-value
pairs on your hard disk.
 The Web server can change name-value pairs or add new pairs
whenever you visit the site and request a page.
 There are other pieces of information that the
server can send with the name-value pair. One of
these is an expiration date. Another is a path
(so that the site can associate different cookie
values with different parts of the site).
 a cookie allows a site to store state information
on your machine
 Web sites use cookies in many different ways--
Sites can accurately determine how many
people actually visit the site.
 Using cookies, sites can determine:
 How many visitors arrive
 How many are new versus repeat visitors
 How often a visitor has visited
 Other than being set by a web server, cookies can
also be set by a script in a language such as
JavaScript, if supported and enabled by the Web
browser.
 In particular, an internet browser is expected to be
able to store at least 300 cookies of four kilobytes
each, and at least 20 cookies per server or domain.
 In practice cookies must be smaller than 4 kilobytes.
Internet Explorer imposes a 4KB total for all cookies
stored in a given domain.
 cookie names are case insensitive.
 To allow the user to see the cookies that are active
with respect to a given page by typing
javascript:alert(document.cookie) in the browser
URL field.
 to access the page http://www.example.org/index.html,
browsers connect to the server www.example.org sending
it a request that looks like the following one:
 GET /index.html HTTP/1.1
Host: www.example.org
browser →
server

 The server replies by sending the requested page


preceded by a similar packet of text, called 'HTTP
response'. This packet may contain lines requesting the
browser to store cookies:
HTTP/1.1 200 OK
Content-type: text/html
Set-Cookie: name=value
(content of page)
Browser ← server
GET /spec.html HTTP/1.1
Host: www.example.org
Cookie: name=value
Accept: */*
Browser →
server
 Beside the name/value pair, a cookie may also contain an
expiration date, a path, a domain name
 For example, a cookie can be created by the server by sending a
line Set-Cookie: name=newvalue; expires=date; path=/;
domain=.example.org.
 The domain and path tell the browser that the cookie has to be
sent back to the server when requesting URLs of a given domain
and path.
 The expiration date tells the browser when to delete the cookie. If
no expiration date is provided, the cookie is deleted at the end of
the user session, that is, when the user quits the browser.
 The expiration date is specified in the "Wdy, DD-Mon-YYYY
HH:MM:SS GMT" format. As an example, the following is a cookie
sent by a Web server (the value string has been changed):
Set-Cookie: RMID=732423sdfs73242; expires=Fri, 31-Dec-2010
23:59:59 GMT; path=/; domain=.example.net
1. JavaScript is very easy to implement. All you need to do is
put your code in the HTML document and tell the browser
that it is JavaScript.
2. JavaScript works on web users’ computers — even when
they are offline!
3. JavaScript allows you to create highly responsive interfaces
that improve the user experience and provide dynamic
functionality, without having to wait for the server to react
and show another page.
4. JavaScript can load content into the document if and when
the user needs it, without reloading the entire page — this
is commonly referred to as Ajax.
5. JavaScript can test for what is possible in your browser and
react accordingly.
6. JavaScript can help fix browser problems or patch holes in
browser support — for example fixing CSS layout issues in
certain browsers.
7. A sign-up form can check if your user name is available
when you enter it, preventing you from having to endure a
frustrating reload of the page.
8. A search box can give you suggested results while you type,
based on what you’ve entered so far (for example “bi”
could bring up suggestions to choose from that contain this
string, such as “bird”, “big” and “bicycle”). This usage
pattern is called autocomplete.
9. Information that changes constantly can be loaded
periodically without the need for user interaction, for
example sports match results or stock market tickers.
10. Information that is a nice-to-have and runs the risk of being
redundant to some users can be loaded when and if the user
chooses to access it. For example the navigation menu of a
site could be 6 links but display links to deeper pages on-
demand when the user activates a menu item.
 What is JS Object Model? And its cookies

You might also like