zoukankan      html  css  js  c++  java
  • cookie的处理

    window.gg = {}
    (function () {
    function setCookie(key, value, options) {
    if (!(getCookie(key) == "")) {
    delCookie(key);
    }
    options = options || {};
    if (value === null || value === undefined) {
    options.expires = -1;
    } else {
    if (options.expires == null) {
    options.expires = new Date();
    options.expires.setFullYear(options.expires.getFullYear() + 1);
    }
    }

    if (typeof options.expires === 'number') {
    var days = options.expires, t = options.expires = new Date();
    t.setDate(t.getDate() + days);
    }
    value = String(value);
    document.cookie =
    [
    encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
    //options.expires ? '; expires=' + options.expires.toUTCString() : '',
    '; expires=' + options.expires.toUTCString(),
    options.path ? '; path=' + options.path : ';path=/',
    options.domain ? '; domain=' + options.domain : '',
    options.secure ? '; secure' : ''
    ].join('');
    }

    function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr == null && name == "LxLoginRoleId") {
    window.location = "index.html";
    }
    return arr == null ? null : decodeURIComponent(arr[2]);
    }

    function delCookie(name) {
    var exp = new Date();
    exp.setFullYear(exp.getFullYear() - 1);
    var cval = getCookie(name);
    var delCookie = name + "=" + cval + ";expires=" + exp.toUTCString() + "; path=/";
    if (cval != null) document.cookie = delCookie;
    }

    gg.core.cookie = {
    setValue: function (key, value, options) {
    if (arguments.length > 1 && String(value) !== "[object Object]") {
    setCookie(key, value, options);
    return;
    }
    },
    getValue: function (key) {
    return getCookie(key);
    },
    deleteCookid: function (key) {
    delCookie(key);
    return;
    }
    };
    })();
  • 相关阅读:
    课堂作业1(出题)
    微信小程序开发1
    asp.net实现通用水晶报表
    JS实现网络拓扑图
    注册与登录 接口与模板
    cookies and session
    Django路由及get请求post请求
    简析JavaScript事件冒泡机制
    屏蔽运营商流量球分析及解决方法
    使用github搭建个人主页
  • 原文地址:https://www.cnblogs.com/tutao1995/p/9777259.html
Copyright © 2011-2022 走看看