<!-- JavaScript:Cookies code snippet 9. -->
<!-- A function to delete a cookie: contains 3 arguments. -->
<!-- Satisfying the requirement to match the same name, path and
domain as when the cookie was created for cookie deletion.  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
// function to delete a cookie containing 3 arguments.
function deleteCookie(name,path,domain)
{
// calls function setCookie() with 5 arguments
// for function setCookie() see JavaScript: Cookies code snippet 8
// note that the expiry date is set to '0' which is 01-Jan-1970 00:00:01 GMT
setCookie(name,'',new Date(0),path,domain)
}
//]]>
</script>
</head>

<body>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
// create a value for the cookie that is to be deleted
var cookieData = escape("name:eric penguin")
// create a new Date object
var expiryDate=new Date()
// set the expiry date of the cookie to 100 days in the future
expiryDate.setTime(expiryDate.getTime() + (1000*60*60*24*100))
// create cookie with setCookie() from JavaScript: Cookies code snippet 8
setCookie('testCookie9',cookieData,expiryDate,'/','justfigures.co.uk')

// call the getCookie() function to write out the value from the cookie
// for function getCookie() see JavaScript: Cookies code snippet 4
document.write("The cookie value is: " + getCookie("testCookie9") + "<br />")

// call the deleteCookie() function to delete the cookie
deleteCookie('testCookie9','/','justfigures.co.uk')

// call the getCookie() function again to see if the cookie exists
document.write("The cookie value is now: " + getCookie("testCookie9"))
//]]>
</script>
</body>
</html>