zoukankan      html  css  js  c++  java
  • js实现cookie跨域功能

    /**
       * 设置cookie方法
       * @param   {string}  name  cookie键值
       * @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));
          } 
        }
        return '';
      }
    

      

    function delCookie(name){
           var exp = new Date();
           exp.setTime(exp.getTime() - 1);
           //获取cookie
           var cval=getCookie(name);
           if(cval!=null)
            document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }
    

      

  • 相关阅读:
    mongo复制集
    s10d71_分组查询_分页_cookie_session_装饰器
    s10_part3_django_ORM_查询相关_非常重要
    s10_part3_django_html模板_view_model
    s10_part3_django_project_library
    记录替换calico为flannel的过程
    kubelet证书过期解决方法
    css
    ubuntu 20.04 ibus添加五笔输入法
    马哥k8s
  • 原文地址:https://www.cnblogs.com/dearxinli/p/7978966.html
Copyright © 2011-2022 走看看