Jeff
04-17-2008, 03:27 AM
I believe I have the right idea, but I am having a hard time making it come together. The problem is to write the current time and date to a cookie during body onUnload. When the user comes back, we are supposed to check for a cookie. If a cookie exist, we are to write the date and time of last visit. If not, we are supposed to welcome the user to the site. When I run this in my Javascript debugger, it comes back with no errors. I'm sure there is something wrong, as it doesn't work. lol
<html>
<head>
<title>cookies</title>
<script type="text/javascript">
function getCurrentTime() {
var today = new Date()
var hour = ""
var exr = ""
if (today.getHours()==0) {
hour = 12
ext = "a.m."
} else if (today.getHours() < 12) {
hour = today.getHours()
ext = "a.m."
} else if (today.getHours() == 12) {
hour = 12
ext = "p.m."
} else {
hour = today.getHours() - 12
ext = "p.m."
}
document.cookies= "cookieName=testcookie; hour=hour.toString(); minute=today.getMinutes().toString(); mille=today.getMilliseconds().toString();pmam=ext)"
}
function getCurrentDate() {
var theday =new Date()
document.cookies= "cookieName=testcookie; monthofvisit=theday.getMonth() + 1; dateofvisit=theday.getDate(); yearofvisit=theday.getFullYear())"
}
</script>
</head>
<body onUnload = "getCurrentTime(), getCurrentDate()">
<script type="text/javascript">
if(document.cookies=true) {
document.write("You last visited us on: ", document.cookies(monthofvisit, dateofvisit, yearofvisit, hour, minute, mille))
} else {
document.write("Welcome this is your first visit to our site")
}
</script>
</body>
</html>
<html>
<head>
<title>cookies</title>
<script type="text/javascript">
function getCurrentTime() {
var today = new Date()
var hour = ""
var exr = ""
if (today.getHours()==0) {
hour = 12
ext = "a.m."
} else if (today.getHours() < 12) {
hour = today.getHours()
ext = "a.m."
} else if (today.getHours() == 12) {
hour = 12
ext = "p.m."
} else {
hour = today.getHours() - 12
ext = "p.m."
}
document.cookies= "cookieName=testcookie; hour=hour.toString(); minute=today.getMinutes().toString(); mille=today.getMilliseconds().toString();pmam=ext)"
}
function getCurrentDate() {
var theday =new Date()
document.cookies= "cookieName=testcookie; monthofvisit=theday.getMonth() + 1; dateofvisit=theday.getDate(); yearofvisit=theday.getFullYear())"
}
</script>
</head>
<body onUnload = "getCurrentTime(), getCurrentDate()">
<script type="text/javascript">
if(document.cookies=true) {
document.write("You last visited us on: ", document.cookies(monthofvisit, dateofvisit, yearofvisit, hour, minute, mille))
} else {
document.write("Welcome this is your first visit to our site")
}
</script>
</body>
</html>