0% found this document useful (0 votes)
43 views2 pages

Delete Cookies

The document contains JavaScript code to create, access, and check cookies. The checkCookie() function is called on page load. It checks for an existing "testCookie" and alerts the stored user name if found. If no cookie exists, it prompts for a user name and number of days to store the cookie, then calls createCookie() to set the "testCookie".

Uploaded by

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

Delete Cookies

The document contains JavaScript code to create, access, and check cookies. The checkCookie() function is called on page load. It checks for an existing "testCookie" and alerts the stored user name if found. If no cookie exists, it prompts for a user name and number of days to store the cookie, then calls createCookie() to set the "testCookie".

Uploaded by

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

<html>

<head>

<title>Cookie!!!</title>

<script type="text/javascript">

function createCookie(cookieName,cookieValue,daysToExpire)

var date = new Date();

date.setTime(date.getTime()+(daysToExpire*24*60*60*1000));

document.cookie = cookieName + "=" + cookieValue + "; expires=" + date.toGMTString();

function accessCookie(cookieName)

var name = cookieName + "=";

var allCookieArray = document.cookie.split(';');

for(var i=0; i<allCookieArray.length; i++)

var temp = allCookieArray[i].trim();

if (temp.indexOf(name)==0)

return temp.substring(name.length,temp.length);

return "";

function checkCookie()

var user = accessCookie("testCookie");


if (user!="")

alert("Welcome Back " + user + "!!!");

else

user = prompt("Please enter your name");

num = prompt("How many days you want to store your name on your computer?");

if (user!="" && user!=null)

createCookie("testCookie", user, num);

</script>

</head>

<body onload="checkCookie()"></body>

</html>

You might also like