Click to See Complete Forum and Search --> : Using a cookie to direct to a certain webpage
Solego
01-13-2004, 01:00 PM
I have an old tired website that is long due for an update. I've finally gotten everyhting set up so that that page will burn down, literally, and the new page will be there for all too see.
What I need is a way to make it so that whoever goes to the burndown site will get a cookie, and whenever they visit that site, it will check for the cookie, and in the event they have it, it will just load the new page without the burn-down effect.
The scripting is all I need, or maybe even just pointers on where to go to figure it out myself :), as everything is set up for the new page to go out.
TheBearMay
01-13-2004, 01:16 PM
This is a little rough, but should point you in the right direction...
<script>
if (GetCookie("Burnt") <= "") {
burnDown();
burntCookie();
}
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 burntCookie(){
var expdate = new Date();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000));
SetCookie("Burnt", new Date(), expdate);
}
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" : "");
}
</script>
Solego
01-13-2004, 02:17 PM
Outstanding, I'll see if I can't get this up and working. I'll post the final code for future reference when I get it up. Thanks for your help.