HTML and CSS Reference
In-Depth Information
Figure 16.10 Retrieve the cookie and welcome the user.
16.2.4 Retrieving Cookies from a Server
When retrieving cookies, you can only get those that were written for the server you are
on and written by you. You cannot read and write cookies that belong to someone else
or reside on a different server. In the last example, we got one cookie; in Example 16.3
all the cookies for this page are displayed.
EXAMPLE 16.3
<html>
<head><title>See my Cookies</title>
<script type="text/javascript">
1
function seeCookie() {
if(document.cookie == ""){
document.write("No cookies");
}
else{
var cookiestr="";
2
var myCookie = document.cookie.split("; ");
3
for(var i=0;i<myCookie.length; i++){
/* document.write("<b>Cookie: " +
myCookie[i].split("=")[1] +"<br />"); */
4
cookiestr+=myCookie[i] + " ";
5
var cookieData=myCookie[i].split("=");
6
if (cookieData[0] == "color"){
7
document.bgColor=cookieData[1];
//Visitor preference to change color
}
 
 
Search WWH ::




Custom Search