Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var redirectPath = "./";
var redirectPage = ["index_second.html","index_third.html","index_fourth.html","index_fifth.html"];
var expDate = new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year
function deleteCookie(isName){
if (getCookie(isName))
{
document.cookie = isName + "="+ "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function setCookie(isName,isValue,dExpires){
document.cookie = isName+"="+isValue+";expires="+dExpires.toGMTString();
}
function getCookie(isName){
var cookieStr = document.cookie;
var startSlice = cookieStr.indexOf(isName+"=");
if (startSlice == -1){return false}
var endSlice = cookieStr.indexOf(";",startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
var isValue = cookieStr.substring(startSlice,endSlice).replace(/^.+\=/,"");
return isValue;
}
function init(){
var visits = getCookie('nVisits');
if (visits)
{
alert('You have been to my web site '+ visits +' times');
visits++;
if (visits < 7)
{
// self.location.href = redirectPath + redirectPage[visits-1];
alert(redirectPath + redirectPage[visits-3]);
}
else {
// self.location.href = redirectPath + redirectPage[redirectPage.length];
alert(redirectPath + redirectPage[redirectPage.length-1]);
}
}
else {
alert('This is your first visit to my site');
visits = 2;
}
setCookie('nVisits',visits,expDate);
}
navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);
</script>
<style type="text/css">
body {background-color: #eae3c6; margin-top: 60px;}
form {width: 620px; margin: auto; font-family: 'times new roman'; font-size: 12pt;}
fieldset {width: 620px; padding-left: 10px; background-color: #f0fff0; border: 1px solid #87ceeb;}
legend {font-family: georgia; font-size: 14pt; color: #00008b; background-color: #87ceeb; padding-left: 3px; padding-right: 3px; margin-bottom: 5px;}
.deleteBtn {background-color: #ffffff; border: 1px solid #000000; font-family: arial; font-size: 10pt; font-weight: bold; cursor: pointer; display: block; margin-left: auto; margin-right: auto; margin-top: 5px; margin-bottom: 5px;}
</style>
</head>
<body>
<form action="" method="post">
<fieldset>
<legend>Form</legend>
<input type="button" value="Delete Cookie" class="deleteBtn" onclick="deleteCookie('nVisits')">
</fieldset>
</form>
</body>
</html>
Bookmarks