限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

jquery轻量级设置、获取、清除和删除session操作插件

所属分类: 网页特效-其它&杂项    2023-11-08 12:42:39

jquery轻量级设置、获取、清除和删除session操作插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery轻量级设置、获取、清除和删除session操作插件(共2个文件)

    • jquery.session.js
    • index.html

使用方法

  • code
  • source
  1. (function($){
  2. $.session = {
  3. _id: null,
  4. _cookieCache: undefined,
  5. _init: function()
  6. {
  7. if (!window.name) {
  8. window.name = Math.random();
  9. }
  10. this._id = window.name;
  11. this._initCache();
  12. // See if we've changed protcols
  13. var matches = (new RegExp(this._generatePrefix() + "=([^;]+);")).exec(document.cookie);
  14. if (matches && document.location.protocol !== matches[1]) {
  15. this._clearSession();
  16. for (var key in this._cookieCache) {
  17. try {
  18. window.sessionStorage.setItem(key, this._cookieCache[key]);
  19. } catch (e) {};
  20. }
  21. }
  22. document.cookie = this._generatePrefix() + "=" + document.location.protocol + ';path=/;expires=' + (new Date((new Date).getTime() + 120000)).toUTCString();
  23. },
  24. _generatePrefix: function()
  25. {
  26. return '__session:' + this._id + ':';
  27. },
  28. _initCache: function()
  29. {
  30. var cookies = document.cookie.split(';');
  31. this._cookieCache = {};
  32. for (var i in cookies) {
  33. var kv = cookies[i].split('=');
  34. if ((new RegExp(this._generatePrefix() + '.+')).test(kv[0]) && kv[1]) {
  35. this._cookieCache[kv[0].split(':', 3)[2]] = kv[1];
  36. }
  37. }
  38. },
  39. _setFallback: function(key, value, onceOnly)
  40. {
  41. var cookie = this._generatePrefix() + key + "=" + value + "; path=/";
  42. if (onceOnly) {
  43. cookie += "; expires=" + (new Date(Date.now() + 120000)).toUTCString();
  44. }
  45. document.cookie = cookie;
  46. this._cookieCache[key] = value;
  47. return this;
  48. },
  49. _getFallback: function(key)
  50. {
  51. if (!this._cookieCache) {
  52. this._initCache();
  53. }
  54. return this._cookieCache[key];
  55. },
  56. _clearFallback: function()
  57. {
  58. for (var i in this._cookieCache) {
  59. document.cookie = this._generatePrefix() + i + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  60. }
  61. this._cookieCache = {};
  62. },
  63. _deleteFallback: function(key)
  64. {
  65. document.cookie = this._generatePrefix() + key + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  66. delete this._cookieCache[key];
  67. },
  68. get: function(key)
  69. {
  70. return window.sessionStorage.getItem(key) || this._getFallback(key);
  71. },
  72. set: function(key, value, onceOnly)
  73. {
  74. try {
  75. window.sessionStorage.setItem(key, value);
  76. } catch (e) {
  77. // doing it after catch defeats purpose of fallback
  78. this._setFallback(key, value, onceOnly || false);
  79. }
  80. return this;
  81. },
  82. 'delete': function(key){
  83. return this.remove(key);
  84. },
  85. remove: function(key)
  86. {
  87. try {
  88. window.sessionStorage.removeItem(key);
  89. } catch (e) {}; //here it's correct because get() returns value from any source
  90. this._deleteFallback(key);
  91. return this;
  92. },
  93. _clearSession: function()
  94. {
  95. try {
  96. window.sessionStorage.clear();
  97. } catch (e) {
  98. for (var i in window.sessionStorage) {
  99. window.sessionStorage.removeItem(i);
  100. }
  101. }
  102. },
  103. clear: function()
  104. {
  105. this._clearSession();
  106. this._clearFallback();
  107. return this;
  108. }
  109. };
  110. $.session._init();
  111. })(jQuery);
(function($){

    $.session = {

        _id: null,

        _cookieCache: undefined,

        _init: function()
        {
            if (!window.name) {
                window.name = Math.random();
            }
            this._id = window.name;
            this._initCache();

            // See if we've changed protcols

            var matches = (new RegExp(this._generatePrefix() + "=([^;]+);")).exec(document.cookie);
            if (matches && document.location.protocol !== matches[1]) {
               this._clearSession();
               for (var key in this._cookieCache) {
                   try {
                   window.sessionStorage.setItem(key, this._cookieCache[key]);
                   } catch (e) {};
               }
            }

            document.cookie = this._generatePrefix() + "=" + document.location.protocol + ';path=/;expires=' + (new Date((new Date).getTime() + 120000)).toUTCString();

        },

        _generatePrefix: function()
        {
            return '__session:' + this._id + ':';
        },

        _initCache: function()
        {
            var cookies = document.cookie.split(';');
            this._cookieCache = {};
            for (var i in cookies) {
                var kv = cookies[i].split('=');
                if ((new RegExp(this._generatePrefix() + '.+')).test(kv[0]) && kv[1]) {
                    this._cookieCache[kv[0].split(':', 3)[2]] = kv[1];
                }
            }
        },

        _setFallback: function(key, value, onceOnly)
        {
            var cookie = this._generatePrefix() + key + "=" + value + "; path=/";
            if (onceOnly) {
                cookie += "; expires=" + (new Date(Date.now() + 120000)).toUTCString();
            }
            document.cookie = cookie;
            this._cookieCache[key] = value;
            return this;
        },

        _getFallback: function(key)
        {
            if (!this._cookieCache) {
                this._initCache();
            }
            return this._cookieCache[key];
        },

        _clearFallback: function()
        {
            for (var i in this._cookieCache) {
                document.cookie = this._generatePrefix() + i + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
            }
            this._cookieCache = {};
        },

        _deleteFallback: function(key)
        {
            document.cookie = this._generatePrefix() + key + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
            delete this._cookieCache[key];
        },

        get: function(key)
        {
            return window.sessionStorage.getItem(key) || this._getFallback(key);
        },

        set: function(key, value, onceOnly)
        {
            try {
                window.sessionStorage.setItem(key, value);
            } catch (e) {
                // doing it after catch defeats purpose of fallback
                this._setFallback(key, value, onceOnly || false);
            }
            return this;
        },
        
        'delete': function(key){
            return this.remove(key);
        },

        remove: function(key)
        {
            try {
            window.sessionStorage.removeItem(key);
            } catch (e) {}; //here it's correct because get() returns value from any source
            this._deleteFallback(key);
            return this;
        },

        _clearSession: function()
        {
          try {
                window.sessionStorage.clear();
            } catch (e) {
                for (var i in window.sessionStorage) {
                    window.sessionStorage.removeItem(i);
                }
            }
        },

        clear: function()
        {
            this._clearSession();
            this._clearFallback();
            return this;
        }

    };

    $.session._init();

})(jQuery);

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 其它&杂项

jquery轻量级可自定义的固定于页面底部可关闭横幅特效代码

rib.js是一个轻量级可自定义的底部横幅插件,当拉动页面滚动条至页面底部后,横幅自动消失隐藏。
  其它&杂项
 5346  0

jquery鼠标拖动table表格边框可调整列宽度插件

一款支持鼠标拖动表格边线自由调整宽度特效,可控制调整到自己想要的表格列宽度,非常的实用。
  其它&杂项
 7391  0

jquery根据窗口大小动态切换CSS文件代码

这是一款可根据当前窗口大小自动切换CSS文件特效,在页面加载时执行,从而加载适合当前窗口大小的CSS。
  其它&杂项
 4523  0

jquery粘性table表格头部固定在顶部特效代码

一款轻量级粘性表格头部插件,当滚动页面时,table表格头部始终固定于页面顶部,非常实用。
  其它&杂项
 8386  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论