//设置
function setCookie(name,value) {
    var Days = 1;
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//读取
function getCookie(name) {
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)) return unescape(arr[2]);
    else return null;
}
//删除
function deleteCookie(name) {
  document.cookie = name+"=;expires="+(new Date(0)).toGMTString();
}

解决方案 »

  1.   

    lz
    -----------------------------------------------------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="zourinet">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <script language="JavaScript">
    /* <![CDATA[ */
    //Set cookies
    function setCookie(name, value) {
       expiryday=new Date();
       expiryday.setTime(expiryday.getTime()+12*60*60*1*1000);
       //保存设置12小时
       document.cookie = name + "=" + escape(value)
       + "; expires=" + expiryday.toGMTString() + ";path=/";
    }
    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 
             end = document.cookie.indexOf(";", offset) 
             if (end == -1) 
                end = document.cookie.length
             return unescape(document.cookie.substring(offset, end))
          } 
       }
       return 0;
    }
    if(getCookie("name")==0)
    {
    // call b page
    window.location.href="B.html";
    //write cookie
    setCookie("name", "name is a value");}
    else
    {
    window.location.href="A.html";
    }
    /* ]]> */
    </script>
    </HEAD><BODY>
    <form method="post" action="">
    <div></div>
    </form>
    </BODY>
    </HTML>
      

  2.   

    我想把,这个代码:
        window.location.href="B.html";
    改成,调用一个外部js文件怎么写呢?
    也就是说,如果没有cookie的时候就调用一个外部js文件
      

  3.   


    lz
    ----------------
    调用外部js?调用外部js里面方法?