• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

“智慧型”网页制作技巧_js

javascript 搞代码 7年前 (2018-06-13) 176次浏览 已收录 0个评论

 人们都希望自己的主页生动活泼,并且多一些与访问者的交互。下面的小技巧是否能让你感到自己的网页多了几分色彩呢?
1.来访者访问次数的记录
 一位来访者看到我能统计他访问我的主页的次数时,非常惊讶,他在留言簿里问我是不是发了黑客程序给他,其实就是下面这段小程序(见程序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 will 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(“我想您是第”+visits+”次来这儿了!很高兴又见到你噢^_^!”)
 // –>
 </script>
 (程序1)
 2.可以根据时间变化的欢迎词
 下面这段小程序能够根据访问者来访的时间的不同而致以不同的欢迎词(见程序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=”你真是个夜猫子!这么晚了还在闲逛,你知道吗?”}
 if (time>=6)
 {var hello=”现在还是挺早的,”}
 if (time>=9)
 {var hello=”小心老板哦,”}
 if (time>=12)
 {var hello=”中午好呀!”}
 if (time>13)
 {var hello=”中午睡觉了吗?”}
 if (time>=18)
 {var hello=”吃晚饭了吗?”}
 if time>19)
 {var hello=”怎么没看电视?”}
 if (time>23)
 {var hello=”已经很晚了,还不去睡觉?你知道不?”}
 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,”现在是北京时间:19″,year,”年”,month,”月”,date,”日,”,hour1,now.getHours(),”点”,m2,now.getMinutes(),”分”,((now.getSeconds()<10)?”0″:””)+now.getSeconds(),”秒了”,”</font>”)
 timerRunning=true
 //end hiding contents –>
 </script>
 (程序2)
 看到这么亲切的问候词,你的访问者一定会多一份对你网页的关心和呵护。

3.访问者所使用的浏览器版本的确定
 <script>
 document.write(“您现在用的是”+navigator.appName+””+navigator.appVersion+”版的浏览器,我猜对了吗?开个玩笑,无论对错,真的很希望您能经常来呦!”)
 </script>
 把这些小程序加到你的网页中试试看,有什么问题可以写信告诉我,地址是 [email protected]

欢迎大家阅读《“智慧型”网页制作技巧_js,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:“智慧型”网页制作技巧_js
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址