zoukankan      html  css  js  c++  java
  • 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));
          } 
        }
      }
    

      

  • 相关阅读:
    02_虚拟机参数
    01_java虚拟机基础入门
    03_模板消息
    Redis 实现分布式锁
    01_微信小程序支付
    python产生随机字符串
    输出的编码
    jmeter MD5加密
    vscode 插件推荐
    appium自动化安装(二)
  • 原文地址:https://www.cnblogs.com/dearxinli/p/8320678.html
Copyright © 2011-2022 走看看