• 适应所有浏览器的cookie


    //设置cookie的方法 weiying
    function SetCookie(a, b) {
        
        var d = new Date();
        var v = arguments;
        var c = arguments.length;
        var e = (c > 2) ? v[2] : null;
        var p = (c > 3) ? v[3] : null;
        var m = (c > 4) ? v[4] : window.location.host;
        var r = (c > 5) ? v[5] : false;
        m = SiteDomain;
        if (e != null) {
            var T = parseFloat(e);
            var U = e.replace(T, "");
            T = (isNaN(T) || T <= 0) ? 1 : T;
            U = ("snhdwmqy".indexOf(U) == -1 || U == "") ? 's' : U.toLowerCase();
            switch (U) {
                case 's': d.setSeconds(d.getSeconds() + T); break;
                case 'n': d.setMinutes(d.getMinutes() + T); break;
                case 'h': d.setHours(d.getHours() + T); break;
                case 'd': d.setDate(d.getDate() + T); break;
                case 'w': d.setDate(d.getDate() + 7 * T); break;
                case 'm': d.setMonth(d.getMonth() + 1 + T); break;
                case 'q': d.setMonth(d.getMonth() + 1 + 3 * T); break;
                case 'y': d.setFullYear(d.getFullYear() + T); break
            }
        }
        else {
            var expiresDays = 360;
            //将date设置为360天以后的时间
            d.setSeconds(d.getSeconds() + expiresDays * 24 * 3600 * 1000);
        }
        var strCookie=a + "=" + escape(b) + ((e == null) ? "" : ("; expires=" + d.toGMTString())) + ((p == null) ? ("; path=/") : ("; path=" + p)) + ("; domain=" + m) + ((r == true) ? "; secure" : "");
        //alert(strCookie);
        document.cookie = strCookie;
    }

    function getCookieVal(a) {
        var b = document.cookie.indexOf(";", a);
        if (b == -1) b = document.cookie.length;
        return unescape(document.cookie.substring(a, b))
    }
    function GetCookie(a) {
        var v = a + "=";
        var i = 0;
        while (i < document.cookie.length) {
            var j = i + v.length;
            if (document.cookie.substring(i, j) == v) return getCookieVal(j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break
        }
        return null
    }
    function delCookie(a) {
        var e = new Date();
        e.setTime(e.getTime() - 1);
        var b = getCookie(a);
        document.cookie = a + "=" + a + ";path=/; domain=" + window.location.host + "; expires=" + e.toGMTString()
    }

  • 相关阅读:
    装饰器 如何理解Python装饰器?
    python装饰器详解
    window 10下安装jdk
    Linux中pam认证详解(上)
    VMware/KVM/OpenStack虚拟化之网络模式总结
    java问题排查命令
    今日面试问题
    Qwtplot3D Qt5.12.0 MinGW 编译运行
    20212022年寒假学习进度06
    Springboot笔记<10>常用注解总结
  • 原文地址:https://www.cnblogs.com/weiying/p/weiying_11_12.html
Copyright © 2020-2023  润新知