Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create cookie if link clicked, redirects to clicked link on next visit

Site has two sections; 'Everywhere' and 'LA'.
Default is 'Everywhere' section.

How would I go about creating a cookie if the visitor clicks the 'LA' section link and when they return to the main site on another visit, they are redirected to that 'LA' section?

I've tried altering this script; http://www.javascriptsource.com/cookies/cookie-redirect.html

Instead of checkboxes, its a link and only one. But doesn't seem to work.

like image 991
Tad Ward Avatar asked Nov 09 '12 17:11

Tad Ward


2 Answers

What I do usually is create a conditional, and create an embed with the cookie inside. I also tend to use this add-on: http://devot-ee.com/add-ons/cookies

like image 157
Christopher Kennedy Avatar answered Oct 27 '22 14:10

Christopher Kennedy


Tad,

For setting the cookie you are going to want to use javascript, using a click handler on the LA section link. If you need some help with setting the cookie in javascript there is a good introductory article at http://www.quirksmode.org/js/cookies.html which isn't bang up to date but is still in full working order.

Once the cookie is set then you will switch to using one of the plugins for EE so that you can check for the existence of it in a template (probably in the an embeded or snippeted template) on page load. If you find the cookie then you can use the standard EE redirect syntax to send the visitor to the relevant section.

like image 2
Adam Wiggall Avatar answered Oct 27 '22 14:10

Adam Wiggall