Create Cookies with one line of code.
Ever struggled to get cookies to work on your Business Catalyst site? Written your own, used 3rd party plugins or just tried to get your head around how the thing works?
We've got a neat little way to easily create and manage your cookies with one line of code.
Cookies are a pretty basic element of web development, but can be a little complicated to understand and use if you're a noob.
But it actually is pretty easy to do.
Ready?
<script> createCookie('CookieName','Your Cookie Value',1); <script>
GASP!
No way, you say? Yes way, Jose. And you can also read and erase cookies with the readCookie('CookieName');
and eraseCookie('CookieName');
functions.
How does all work?
You may not be aware, but BC already uses cookies throughout the system, especially with the eCommerce functionality. If you look at the source code for the shopping cart you'll see the Java_Cookies.js
script.
By piggy-backing off the built-in code you'll avoid duplicating sometimes conflicting scripts meaning less hair pulling and more key punching.
Just remember though, like any BC feature, they can change it at any time. But it's a fairly standard script, and well integrated into the system so I think you'll have more than enough notice to implement changes into new sites.
1 Comments so far
frompaul wright 19-Nov-2012 08:23 PM