«
记住来访网友名字的特效

时间:2010-6-11    作者:Deri    分类: 分享


   <p><code><html><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><br /><title>记住来访网友名字.</title><br /><script language="javascript"><br /><!--<br />var username = GetCookie('username');<br />if (username == null) {<br />username = prompt('第一次光临我的主页的朋友,请输入您的名字',"");<br /> if (username == null) {<br />  alert('Its ok if you dont want to tell me your name');<br />  username = 'WebSurfer';<br /> } else {<br />  // don't set the username cookie.... because the user refused to tell you.<br />  // they will be prompted next time....<br />  pathname = location.pathname;<br />  myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';<br />  // set expiry date to 1 year from now.<br />  var largeExpDate = new Date ();<br />  largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));<br />  SetCookie('username',username,largeExpDate,myDomain);<br /> }<br />}<br />function getCookieVal (offset) {<br />  var endstr = document.cookie.indexOf (";", offset);<br />  if (endstr == -1)<br />   endstr = document.cookie.length;<br /> return unescape(document.cookie.substring(offset, endstr));<br />}<br />function GetCookie (name) {<br />    var arg = name + "=";<br />   var alen = arg.length;<br />    var clen = document.cookie.length;<br />    var i = 0;<br />    while (i < clen) {<br />        var j = i + alen;<br />        if (document.cookie.substring(i, j) == arg)<br />            return getCookieVal (j);<br />        i = document.cookie.indexOf(" ", i) + 1;<br />            if (i == 0)<br />                break;<br />        }<br />  return null;<br />}<br />function SetCookie (name, value) {<br />    var argv = SetCookie.arguments;<br />    var argc = SetCookie.arguments.length;<br />    var expires = (argc > 2) ? argv[2] : null;<br />    var path = (argc > 3) ? argv[3] : null;<br />    var domain = (argc > 4) ? argv[4] : null;<br />    var secure = (argc > 5) ? argv[5] : false;<br />    document.cookie = name + "=" + escape (value) +<br />        ((expires == null) ? "" : ("; expires=" +<br />expires.toGMTString())) +<br />        ((path == null) ? "" : ("; path=" + path)) +<br />        ((domain == null) ? "" : ("; domain=" + domain)) +<br />        ((secure == true) ? "; secure" : "");<br />}<br />document.write('<p>谢谢您光临我的网页, '+username);<br />//--></script><br /></head><br /><body><br />  <br /><p></p><br /><p></p>                          <br />  <br /></body><br /></html></code></p>