PDA

View Full Version : How do you redirect a return visitor?



MrCorby
08-24-2006, 08:49 PM
Is it possible to create a cookie using javascript that will redirect a return visitor to the page last viewed? For example if a user completes only half of a 20 page tutorial then quits the browser. When he returns, can he be redirect to where he left off?

mburt
08-27-2006, 01:38 PM
Check out this:


<html>
<head>
<script type="text/javascript">
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 (cookieName) {

var arg = cookieName + "=";
var argLength = arg.length;

var cookieLength = document.cookie.length;

var i = 0;

while (i < cookieLength) {
var j = i + argLength;


if (document.cookie.substring(i, j) == arg) {

return getCookieVal(j)
}

if (i == 0) {
break
}
}
return null;
}

function setCookie(name, value) {


var argv = setCookie.arguments;

var argc = setCookie.arguments.length;

var expires = (argc > 2) ? argv[2] : null;

var path = (argc > 3) ? argv[3] : null;

var domain = (argc > 4) ? argv[4] : null;

var secure = (argc > 5) ? argv[5] : false;

document.cookie = name + "=" + escape(value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function register(userName, value) {

if (userName == "" || userName == null) {

userName = "Unknown User"
}


if(getCookie('myCookie') == null) {

var expdate = new Date()

expdate.setTime(expdate.getTime() + (1000 * 60 * 60 * 24 * 365));

setCookie('myCookie', userName, expdate);
alert ("Thank you for registering, " + userName + "! Click OK to enter the registered portion of my site.");

location.href = "list0602.htm"

}
}
if(getCookie('myCookie') != null) {
location.href="list0602.htm"
}
</script>
</head>
<body>
<form name="loginForm">
<input type="text" name="fullName" size=35>
<br>
<input type="button" value="Register" onclick="register(loginForm.fullName.value)">
</form>
</body>
</html>

Alldaron
07-27-2012, 06:49 PM
Did the above work for you? I'm intending to implement a Here's What's New Since Your Last Visit page