"Smart" Web page making Tips

Source: Internet
Author: User
Tags date return setcookie sleep version domain
Tips | People want their home page to be lively and have more interaction with their visitors. Do the following tips make you feel a bit more colorful on your Web page?
1. A record of the number of visitors visited
A visitor saw that I was able to count the number of times he visited my homepage, and was surprised that he asked me in the guest book whether I had sent a hacker program to him, which is actually the following small procedure (see Program 1).
<script
Language= "JavaScript" >
<!--
var caution = False
function Setcookie (name,value,expires,path,domain,secure) {
var curcookie=name+ "=" +escape (value) +
((expires)? "; Expires= "+expires.togmtstring ():" ") + ((path)?"; Path= "+path:" "") + domain)? domain= "+domain:" "+ (Secure)?"; Secure ":" ")
if (!caution | | (name+ "=" +escape (value)). length<=4000)
Document.cookie=curcookie
Else
if (Confirm ("Cookie exceeds 4KB and would be cut!"))
Document.cookie=curcookie
}
function GetCookie (name) {
var prefix = name + "="
var cookiestartindex=document.cookie.indexof (prefix)
if (Cookiestartindex = = 1)
return null
var cookieendindex=document.cookie.indexof (";", Cookiestartindex+prefix.length)
if (Cookieendindex = = 1)
Cookieendindex=document.cookie.length
Return unescape (document.cookie.substring cookiestartindex+prefix.length,
Cookieendindex))
}
function Deletecookie (name, path, domain) {
if (GetCookie (name)) {
Document.cookie=name+ "=" + ((path)?; Path= "+path:" ") + ((domain)?"; domain= "+domain:" ") +"; expires=thu,01-jan-70 00:00:01 GMT "
}
}
function Fixdate (date) {
var base = new Date (0)
var skew = Base.gettime ()
if (Skew > 0)
Date.settime (Date.gettime ()-skew)
}
var now = new Date ()
Fixdate (now)
Now.settime (Now.gettime () +365*24*60*60*1000)
var visits = GetCookie ("Counter")
if (!visits)
Visits = 1
Else
visits = parseint (visits) + 1
Setcookie ("Counter", visits, now)
document.write ("I think you are the first" +visits+ "Time to come here!) Nice to see you again, OH ^_^! "
-->
</script>
(Procedure 1)
2. Welcome words that can vary according to time
The following applet will offer different welcome words depending on the time of the visitor's visit (see Program 2).
<script
Language= "Javascript" >
<!--hiding
var now = new Date ()
var year=now.getyear ()
var month=now.getmonth () +1;
var date= now.getdate ()
var time = now.gethours ()
if (time>=0)
{var hello= "You're a night owl!" you know? "}
if (time>=6)
{var hello= "is still very early,"}
if (time>=9)
{var hello= "Beware of the Boss,"}
if (time>=12)
{var hello= "Good afternoon!" "}
if (time>13)
{var hello= "Did you sleep at noon?"}
if (time>=18)
{var hello= "Have you had dinner?" "}
If time>19)
{var hello= "Why didn't you watch TV?"}
if (time>23)
{var hello= "is very late, do not go to sleep?" You know what? "}
var hour1= (now.gethours () >=10)? "": "0"
var m2= (Now.getminutes () >=10)? "": "0"
var t= (now.gethours () >12)? Now.gethours () -12:now.gethours ()
var r2 = (T >= 10)? "" : ""
var color= (Now.getseconds ()%2==0)? " Ffff80 ":" 00000f "
Dcument.write ("<font color=\", Color, ">", Hello, "Now is Beijing Time:", Year, "Years", Month, "month", date, "Day,", Hour1, Now.gethours (), "Point", M2,now.getminutes (), "Min" ((Now.getseconds () <10)? 0 ":" "+now.getseconds" (), "seconds", "</font>")
Timerrunning=true
End Hiding contents-->
</script>
(Procedure 2)
See such a cordial greeting, your visitors will be more than one to your Web site care and care.

3. The browser version used by the visitor is determined
<script>
document.write ("You are now using the" +navigator.appname+ "" +navigator.appversion+ "version of the browser, I guess right?) A joke, whether right or wrong, really hope you can often come yo! ")
</script>
Add these small programs to your Web page and try to see if there are any questions you can write to tell me, address is doggy007@188.net.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.