JS读写浏览器cookie及读取页面参数
var zbrowser = { //设置浏览器cookie,exdays是cookie有效时间 setCookie: function (c_name, value, exdays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value = value + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()); document.cookie = c_name + "=" + c_value; }, //获取浏览器cookie getCookie: function (c_name) { var c_value = document.cookie; var c_start = c_value.indexOf(" " + c_name + "="); if (c_start == -1) { c_start = c_value.indexOf(c_name + "="); } if (c_start == -1) { c_value = null; } else { c_start = c_value.indexOf("=", c_start) + 1; var c_end = c_value.indexOf(";", c_start); if (c_end == -1) { c_end = c_value.length; } c_value = c_value.substring(c_start, c_end); } return c_value; }, //获取页面参数:http://www.xxx.com?va=1;---> getPageVar("va")=1 getPageVar: function (sVar) { return location.search.replace(new RegExp("^(?:.*[&\\?]" + sVar.replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"); } };