Return to Snippet

Revision: 687
at July 31, 2006 04:36 by markhope


Updated Code
<script type="text/javascript">
	// adapted from http://evolt.org/article/list/20/416/
		// <![CDATA[
	var Splash = GetCookie('SplashSkip');


	ReDirect('/welcome');

	function ReDirect (URL) {

		SetCookie('SplashSkip','TRUE',1);

		if (Splash == 'TRUE') {

			window.location=(URL);
		}
	}

	function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
	    endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}

	function GetCookie (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	  var j = i + alen;
	  if (document.cookie.substring(i, j) == arg)
	    return getCookieVal (j);
	  i = document.cookie.indexOf(" ", i) + 1;
	  if (i == 0) break; 
	  }
	  return null;
	}

	function SetCookie(name, value, expDays, path, domain, secure) {
		// Set cookie with name, value etc provided
		// in function call and date from above
		// Number of days the cookie should persist NB expDays='' or undef. => non-persistent
		if (expDays != null ) {
			var expires = new Date(); 
			expires.setTime(expires.getTime() + (expDays*24*60*60*1000));
		}	
		var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}
		// ]]>
	</script>

Revision: 686
at July 31, 2006 04:33 by markhope


Initial Code
<script type="text/javascript">
	// adapted from http://evolt.org/article/list/20/416/
		// <![CDATA[
	var Splash = GetCookie('SplashSkip');


	ReDirect('/welcome');

	function ReDirect (URL) {

		SetCookie('SplashSkip','TRUE',1);

		if (Splash == 'TRUE') {

			window.location=(URL);
		}
	}

	function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
	    endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}

	function GetCookie (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	  var j = i + alen;
	  if (document.cookie.substring(i, j) == arg)
	    return getCookieVal (j);
	  i = document.cookie.indexOf(" ", i) + 1;
	  if (i == 0) break; 
	  }
	  return null;
	}

	function SetCookie(name, value, expDays, path, domain, secure) {
		// Set cookie with name, value etc provided
		// in function call and date from above
		// Number of days the cookie should persist NB expDays='' or undef. => non-persistent
		if (expDays != null ) {
			var expires = new Date(); 
			expires.setTime(expires.getTime() + (expDays*24*60*60*1000));
		}	
		var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}
		// ]]>
	</script>

Initial URL


Initial Description
redirects a splash page if visited before. Number of days until expiry can be set

Initial Title
Redirect cookie

Initial Tags
javascript, redirect, textmate

Initial Language
JavaScript