js cookie

 有些变量未定义

function getcookief(name, nounescape) {
		var cookie_start = document.cookie.indexOf(name);
		var cookie_end = document.cookie.indexOf(";", cookie_start);
		if(cookie_start == -1) {
			return '';
		} else {
			var v = document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length));
			return !nounescape ? unescape(v) : v;
		}
	
	}
	
	function setcookief(cookieName, cookieValue, seconds, path, domain, secure) {
		var expires = new Date();
		if(cookieValue == '' || seconds < 0) {
			cookieValue = '';
			seconds = -2592000;
		}
		expires.setTime(expires.getTime() + seconds * 1000);
		domain = !domain ? cookiedomain : domain;
		path = !path ? cookiepath : path;
		document.cookie = escape(cookieName) + '=' + escape(cookieValue)
			+ (expires ? '; expires=' + expires.toGMTString() : '')
			+ (path ? '; path=' + path : '/')
			+ (domain ? '; domain=' + domain : '')
			+ (secure ? '; secure' : '');
	}

 cookiedomain和cookipath需定义

也可去掉?

function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	if(cookieValue == '' || seconds < 0) {
		cookieValue = '';
		seconds = -2592000;
	}
	expires.setTime(expires.getTime() + seconds * 1000);
	domain = !domain ? '' : domain;
	path = !path ? '' : path;
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

 

你可能感兴趣的:(cookie)