js cookie跨域設置


/**
   * 設置cookie方法
   * @param   {string}  c_name  cookie鍵值
   * @param   {string}  value  cookie值
   * @param   {Boolean}  domain  判斷是否需要跨域
   * @return  {*}  返回cookie值
   */
function setCookie_log (c_name,value,domain){
    var exdate = new Date(), expiredays = 365;
    exdate.setDate(exdate.getDate() + expiredays);
    //判斷是否需要跨域存儲
    if (domain) {
        document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/;domain=xueersi.com";
    } else {
        document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
    }    
  }
  /**
   * 獲取cookie方法
   * @param   {string}  name  cookie鍵值
   * @return  {*}  返回cookie值
   */
  function getCookie_log(name){
    if (document.cookie.length>0){
      var start=document.cookie.indexOf(name + "=");
      if(start != -1){ 
        start = start + name.length + 1;
        var end = document.cookie.indexOf(";",start);
        if (end == -1){
          end = document.cookie.length;
        }
        return unescape(document.cookie.substring(start,end));
      } 
    }
  }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM