English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have found a script for redirecting based on cookies... code below:



basically the script says that if the cookie (animal) is true, the page will be redirected. but i want the code to say if the cookie (animal) is not there, or is false, then it will redirect, how would i do that?

alex

2006-06-12 08:38:00 · 2 answers · asked by alco19357 5 in Computers & Internet Programming & Design

2 answers

Its the start(-1)

If its -1, then youre saying it did not find it so set it. If you did find it then it does the else (which is the redirect).

Just change it to start(1) or switch the if and else conditions like this:
if (start == -1){
window.location = go_to;
} else {
document.cookie = "seenit=yes; expires=" + ged(num_days);
}

2006-06-12 08:46:27 · answer #1 · answered by Sean I.T ? 7 · 0 0

That function looks pretty specific to that application. There are three functions available at http://www.quirksmode.org/js/cookies.html that will prove very useful for any cookie application. To achieve the effect you want, you would use quirksmode's readCookie function, which will return NULL if the cookie is not set.

So to redirect, you'd have something like:
if(!readCookie("animal"))
{
window.location = "http://myredirect.com";
}

You should note that if you're using this to keep people from being somewhere they're not suppoed to be, you might want to consider some server side processing instead of javascript, or at least do some checks on the cookie that are more involved than just checking to see if it exists.

2006-06-12 08:51:45 · answer #2 · answered by Jody 3 · 0 0

fedest.com, questions and answers