Call us

Catfish gets a makeover part 2

Tutorials 1 comment

Going back to my original post on the catfish makeover, I was contacted about the cookie modification that I made to the script.

Basically, what I did was on the “close” link in the catfish popup, I added the code to put a cookie on the visitors machine. Then on the code that actually launches the catfish, I did a quick cookie check to see if my cookie had been set. If it had, don’t display the catfish.

Here’s how I did it:

In the catfish.js file that you need to attach to each page, right at the top, add the following function:

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

Now in the same file, right at the bottom find the line that reads

$.closeCatfish = function() {

Add this right below it

createCookie('cat','1','30')

The ‘cat’ part is the name of your cookie, the ‘1′ is it’s value and the ‘30′ is the number of days it is set for.

How to check for the cookie before deploying the catfish

This is the relatively easy part. I use classic ASP VbScript so here’s the code:

if request.Cookies("cat") <> “1″ then

catfish code goes here

end if

That’s it folks. If you’re using another language like php or something you’ll obviously have to adjust the last cookie check bit.

For a working demo, visit ClickCMS

Related Posts

One Response to “Catfish gets a makeover part 2”

  1. » Catfish gets a makeover Web Design and Development Blog: a journey into elegant web design and best practices Says:

    [...] Update: Here’s how I added the cookie check [...]

Leave a Comment