//记录某人的访问量 <html> <head> <title>Listing 25.2. Getting and Setting Multiple Cookies</title> </head><body><script language="JavaScript" type="text/javascript"> <!--function get_cookie(name_to_get) { var cookie_pair var cookie_name var cookie_value
// Split all the cookies into an array var cookie_array = document.cookie.split("; ")
// Run through the cookies for (counter = 0; counter < cookie_array.length; counter++) {
// Split the cookie into a name/value pair cookie_pair = cookie_array[counter].split("=") cookie_name = cookie_pair[0] cookie_value = cookie_pair[1]
// Compare the name with the name we want if (cookie_name == name_to_get) {
// If this is the one, return the value return unescape(cookie_value) } }
// If the cookie doesn't exist, return null return null }// Get the user_name cookie var user_name = get_cookie("user_cookie")// Did the cookie exist? if (!user_name) { // If not, prompt for the name user_name = prompt("Please enter your first name:","")
// Set the cookie document.cookie = "user_cookie=" + escape(user_name) }// Get the count cookie var visit_number = get_cookie("count_cookie")// Did the cookie exist? if (!visit_number) { // If not, then this is the user's first visit visit_number = 1 document.writeln("Welcome " + user_name + ". This is your first visit.") } else { // Otherwise, increment the visit number visit_number++ document.writeln("Welcome " + user_name + ". This is visit number " + visit_number + ".") }// Set the cookies document.cookie = "count_cookie=" + visit_number //--> </script></body> </html>
你留下email回头给你发一段asp的站点计数器
3。网站自某日起的总访问量计数;
js可以实现
<html>
<head>
<title>Listing 25.2. Getting and Setting Multiple Cookies</title>
</head><body><script language="JavaScript" type="text/javascript">
<!--function get_cookie(name_to_get) { var cookie_pair
var cookie_name
var cookie_value
// Split all the cookies into an array
var cookie_array = document.cookie.split("; ")
// Run through the cookies
for (counter = 0; counter < cookie_array.length; counter++) {
// Split the cookie into a name/value pair
cookie_pair = cookie_array[counter].split("=")
cookie_name = cookie_pair[0]
cookie_value = cookie_pair[1]
// Compare the name with the name we want
if (cookie_name == name_to_get) {
// If this is the one, return the value
return unescape(cookie_value)
}
}
// If the cookie doesn't exist, return null
return null
}// Get the user_name cookie
var user_name = get_cookie("user_cookie")// Did the cookie exist?
if (!user_name) { // If not, prompt for the name
user_name = prompt("Please enter your first name:","")
// Set the cookie
document.cookie = "user_cookie=" + escape(user_name)
}// Get the count cookie
var visit_number = get_cookie("count_cookie")// Did the cookie exist?
if (!visit_number) { // If not, then this is the user's first visit
visit_number = 1
document.writeln("Welcome " + user_name + ". This is your first visit.")
}
else { // Otherwise, increment the visit number
visit_number++
document.writeln("Welcome " + user_name + ". This is visit number " + visit_number + ".")
}// Set the cookies
document.cookie = "count_cookie=" + visit_number
//-->
</script></body>
</html>