tags:

views:

50

answers:

2

Hi. I am designing a website that has 100% width + height div containing a graphic overlaying the home page. I want to show this once to the user when they first visit the site, a kind of welcome to the site click here to enter then this would never been shown to that user again.

How do I write a cookie with Jquery to do this? Many thanks.

+2  A: 

You can try using the jQuery Cookie Plugin.

The cookie is a form of persistent storage. When a user loads the page, you check if he has a certain cookie. If he doesn't, you show him the splash page and set the cookie. If he has the cookie set that means he's been here before and you don't need to do anything. The following code could be a solution, but I'm writing it out of my head so you'd probably have to modify it a bit. It assumes you're using the plugin above.

if (visits = $.cookie('noOfVisits')) {
    $.cookie('noOfVisits', visits++);
} else {
    $.cookie('noOfVisits', 1);
    $('#splash').show();
}

I think that it's pretty self explanatory. Note that the cookie expires, research how to make it last as long as you want.

Hope this helps :).

Alex Ciminian
Thanks Alex. I am still unsure how I apply the cookie to the specific task I want i.e stop a div from showing itself again. Can you help with that?
mtwallet
Please see the updated post. Cheers!
Alex Ciminian
That explains it perfectly Alex thanks for the help I appreciate it.
mtwallet
A: 

Using Google, I found this very easy to understand explanation of handling cookies with JQuery: http://www.electrictoolbox.com/jquery-cookies/

oskarae
Yes oskarae I saw that too but I am still unsure how I apply the cookie to the specific task I want i.e stop a div from showing itself again. Can you help with that?
mtwallet
I am not what you mean mtwallet. What exactly you wish to do?
oskarae