PDA

View Full Version : Boolean Loops With Cookie Behavior


doublehelix3216386358
08-11-2009, 04:29 AM
Be gentle with me, I am quite the novice... ;)

Basic scenario:

I have a page (call it "page 1") with a link to go to a form page. Once complete, this form sets a cookie, and takes users to a download page. On subsequent visits, I would like the users to be able to skip the form page altogether and go directly from "page 1" to the download page.

Through the use of your program, I have got this working, sort of, but it is not ideal.

First, I can get the form to set the cookie, that is easy. It is the redirection that is not as clean as I would like it to be.

I cannot find a way to make the original link on "page 1" send the user to the correct page based on the cookie. I would like that link to make the *decision*, cookie = "yes", go to download page, cookie = "no", go to form page.

What I ended up doing was keeping the link on "page 1" to go to the form page only, but then on the form page, I used the "Redirect based on cookie" behavior, set to "On Load" for a small graphics file on the form page, which sends the user to the download page if the cookie exists. This means that the form page starts to load, but then redirects almost immediately. This causes a bit of a jerky hitch in the transition between "page 1" and the download page for those that already have the cookie.

When I look at the code for the cookie redirection, it looks like this:

"WA_cookieRedirect(WA_CookieObj,document,true,'TB_D ownload_Form','1','Downloadmusic.html',false)" />

It looks like I should be able to use this code with the original link on "page 1", yet add in a value for the "false" parameter so that the original link will make the decision to do the redirection based on the cookie. I have tried several permutations of this, but I cannot seem to get it to work.

Basically, a Boolean loop... "If, then, else" type of redirection.

Is this possible with this program? If so, would you be so kind as to supply me with the correct syntax?

Thanks in advance.

Eric Mittman
08-11-2009, 04:32 PM
You are already implementing this in the correct way, you just have your redirect too far down on the page. You should move the redirect code so that it is in the head above any other script or image preloading, it can be the first thing in the head. This way the page will not load up then redirect, instead the user will click the link, the form page will attempt to load but before anything is displayed on the page at all it will go to the download page.

doublehelix3216386358
08-11-2009, 05:03 PM
Thank you Eric, however, I was unable to get your solution to work as you suggested.

I copied the following line of code to the very first line below the <head> tag:

onload="WA_cookieRedirect(WA_CookieObj,document,true,'TB_D ownload_Form','1','Downloadmusic.html',false)"


Nothing happened.

Do I need to enclose the line between "<" and ">" (or "/>")? Am I missing something else?

Remember, I am a novice, so you need to be *very* specific! :)

Doesn't the function:
"function WA_cookieRedirect"

need to be loaded before that command?


Also, there is no way to add this using the Behaviors window into the location you suggest. It has to be added elsewhere, and then cut and pasted into position. Not a biggie I suppose, but it would be much nicer if you could implement the Boolean logic into the command as I originally suggested.

Eric Mittman
08-13-2009, 04:43 PM
It will not work to have the onload event trigger the redirect based on the cookie because this event is only valid for the body tag.

Instead you will need to put this in a script block like this:

<script type="text/javascript">
WA_cookieRedirect(WA_CookieObj,document,true,'TB_D ownload_Form','1','Downloadmusic.html',false);
</script>

Make sure that you have this function defined before this line of code appears. Other than that it should load this code, check the cookie, then do the redirect.

doublehelix3216386358
08-13-2009, 05:17 PM
Thank you, that did the trick.

I really appreciate your help.

Eric Mittman
08-14-2009, 08:14 PM
No problem, I'm happy to hear that it worked out for you.