function set_cookie(key, value, exp, path, domain, secure) { path = "/"; var cookie_string = key + "=" + escape(value); if (exp) { cookie_string += "; expires=" + exp.toGMTString(); } if (path) cookie_string += "; path=" + escape(path); if (domain) cookie_string += "; domain=" + escape(domain); if (secure) cookie_string += "; secure"; document.cookie = cookie_string; } /*读取 cookie*/ function get_cookie(cookie_name) { var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); if (results) return (unescape(results[2])); else return null; } /*删除 cookie*/ function del_cookie(cookie_name) { var cookie_date = new Date(); //current date & time cookie_date.setTime(cookie_date.getTime() - 1); document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString(); }