JavaScript,js读写cookie

    xiaoxiao2022-07-02  124

    /* 读取cookie工具 */ window.readCookie = function (name) { var nameEQ = name + '='; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length, c.length); } } return null; }; // minutes保存分鐘數 //_Tdom限制在什麼目錄 下,默認全站 window.createCookie = function (name, value, minutes, _Tdom) { var Tdom = _Tdom || '/'; var date, expires; if (minutes) { date = new Date(); date.setTime(date.getTime() + (minutes * 60 * 1000)); expires = '; expires=' + date.toGMTString(); } else { expires = ''; } document.cookie = name + '=' + value + expires + '; path=' + Tdom; };

     

    最新回复(0)