<HTML> <!-- ARCHIVE by FORTUNECITY.ws --> <HEAD> <TITLE>Cookies (Suzanne Stagel's JavaScript Assignment #5 Part II) </TITLE> <SCRIPT language="JavaScript"> function getCookieData(label) { var labelLen = label.length; var cLen = document.cookie.length; var i = 0; var cEnd; while (i < cLen) { var j =i + labelLen; if (document.cookie.substr(i,j) == label) { cEnd = document.cookie.indexOf(";",j); if (cEnd == -1) { cEnd = document.cookie.length; } return unescape(document.cookie.substring(j,cEnd)); } i++; } return ""; } function setCookie(cookieName,cookieValue,cookieExpDate) { //Update cookie document.cookie = cookieName + "=" + cookieValue + "; expires=" + cookieExpDate.toGMTString(); } </SCRIPT> <SCRIPT language="JavaScript"> function displayWelcome() { var cookieName = "numVisits"; var welcomeMsg; var numVisits = -1; var exp; var oneYearFromNow; //Get numVisits cookie from user's machine numVisits = getCookieData((cookieName + "=")); //Create welcome message welcomeMsg = "<H1><CENTER>Welcome! You've visited this page " + numVisits + " times. <BR>Thank you for coming!</CENTER></H1>"; //Define cookie expiration exp = new Date(); oneYearFromNow = exp.getTime() + (365*24*60*60*1000); exp.setTime(oneYearFromNow); //Set numVisits cookie setCookie(cookieName,++numVisits,exp); //Return welcome message return (document.write(welcomeMsg)); } </SCRIPT> </HEAD> <BODY bgcolor="navyblue" text="yellow" link="pink" vlink="purple"><script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-47423994-1', 'fortunecity.ws'); ga('send', 'pageview'); </script> <center> <br> <div> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=728&height=90"></script> </div> </center> <center> <br> <div style="height:5px"></div> </center> <SCRIPT language="JavaScript"> displayWelcome(); </SCRIPT> </BODY> <!-- ARCHIVE by FORTUNECITY.ws --> <center> <div> <br> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=300&height=250&cache=0"></script> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=300&height=250"></script> </div> <br> <br> </center> </HTML>