cookieutil.js

来自「Portal C# Article Live」· JavaScript 代码 · 共 4 行

JS
4
字号

    function getCookieValue(name) 
      { 
        var cookieString = document.cookie; 
        var index = cookieString.indexOf(name + "="); 

        if (index == -1) return null; 

        index = cookieString.indexOf("=", index) + 1; 
        var endstr = cookieString.indexOf(";", index); 

        if (endstr == -1) endstr = cookieString.length; 

		return unescape(cookieString.substring(index, endstr));
      } 
      
      
    function setCookieValue(cookieName, cookieValue, cookiePath, cookieExpires) 
      { 
        cookieValue = escape(cookieValue); 
        if (cookieExpires == "") 
          { 
            var nowDate = new Date(); 
            nowDate.setMonth(nowDate.getMonth() + 6); 
            cookieExpires = nowDate.toGMTString();
          }

        if (cookiePath != "") 
          {
            cookiePath = ";Path=" + cookiePath; 
          } 

       document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath;
      }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?