var getQueryString = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return ''; } var getCookie = function (name) { var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return false; } var setCookie = function (name, value) { var Days = 3000; var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); } var S4 = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); } var guid = function () { return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); } var getUid = function () { var uidInStorage = localStorage.getItem("uid"); var uidInCookie = getCookie("uid"); var uid = uidInStorage || uidInCookie || guid(); localStorage.setItem("uid", uid); setCookie("uid", uid); return uid; }