当前位置:编程学习 > JS >>

利用Cookis制作的导航效果

利用Cookis制作的导航效果,链接在图片上面,鼠标移上去后会看到链接,当你点击一次的时候,就能记得,下次就直接进入这个站了。
答案:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Cookis制作的导航菜单效果</TITLE>
</HEAD>
<BODY>
<script languague="javascript1.2">
<!--
function setCookie(value, expires, domain) {
  var curCookie = "home=" + escape(value) + "; expires=" + expires.toGMTString() + "; domain=" + domain;
  document.cookie = curCookie;
}

function getCookie(Name) {
        var search = Name + "=";
        if (document.cookie.length > 0) {
                // if there are any cookies
                offset = document.cookie.indexOf(search);
                if (offset != -1) {
                        // if cookie exists
                        offset += search.length;
                        // set index of beginning of value
                        end = document.cookie.indexOf(";", offset);
                        // set index of end of cookie value
                        if (end == -1)
                                end = document.cookie.length;
                        return unescape(document.cookie.substring(offset, end));
                }
        }
}

function setHome(myhome){
        var today = new Date();
        var expires = new Date();
        var domainName = "tom.com";
        expires.setTime(today.getTime() + 1000*60*60*24*365);
        if (document.homeform.setgo.checked){
                setCookie(myhome,expires,domainName);
        }
        switch (myhome){
                case "cn":
                        document.location = "http://cn.tom.com/";
                        break;
                case "sh":
                        document.location = "http://sh.tom.com/";
                        break;
                case "gz":
                        document.location = "http://gz.tom.com/";
                        break;
                case "hk":
                        document.location = "http://hk.tom.com/";
                        break;
                case "eng":
                        document.location = "http://us.tom.com/";
                        break;
        }

}

var pHome = getCookie("home");
if (pHome){
        switch (pHome){
                case "cn":
                        document.location = "/";
                        break;
                case "sh":
                        document.location = "http://www.baidu.com/";
                        break;
                case "gz":
                        document.location = "http://www.zhaoxi.net/";
                        break;
                case "hk":
                        document.location = "http://www.qq.com/";
                        break;
                case "eng":
                        document.location = "http://www.sina.com/";
                        break;
        }
}
//-->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="98%">
  <tr align="center"> 
    <td> 
      <table width="480" border="0" cellspacing="0" cellpadding="0">
               <tr valign="top" align="center"> 
          <td height="145"><img src="/jscss/demoimg/wall_s3.jpg" width="480" height="145" usemap="#Map" border="0"><map name="Map"><area shape="rect" coords="351,37,468,78" href="javascript:setHome('hk')"><area shape="rect" coords="9,37,100,78" href="javascript:setHome('cn')"><area shape="rect" coords="107,37,213,78" href="javascript:setHome('sh')"><area shape="rect" coords="222,37,344,78" href="javascript:setHome('gz')"><area shape="rect" coords="141,91,314,116" href="javascript:setHome('eng')"></map></td>
        </tr>
      </table>
    </td>
  </tr>
   <tr align="center"> 
    <td> 
      <table width="400" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td valign="top"> 
            <form name="homeform" method="post">
              <input type="checkbox" name="setgo" value="1">下次直接进入这个分站...
            </form>
          </td>
         </tr>
      </table>
    </td>
  </tr>
</table>
</BODY>
</HTML>

上一个:jQuery hover合成事件
下一个:跟随鼠标的方块

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,