Zander
Zander

Reputation: 2684

How, with jQuery do I tell if a website visitor has been to the site before?

I want create a div container with a message for first time visitors to my site. Visitors will read it and click a 'Hide' button to dissapear it forever.

How is this done?

Upvotes: 5

Views: 2169

Answers (2)

bart
bart

Reputation: 15298

You can accomplish this by:

  1. Setting a cookie.
  2. Storing the status in a session.

You can do 1. with JavaScript but also with PHP. 2. can only be accomplished server-side with e.g. PHP.

This tutorial may be helpful: http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/

Upvotes: 0

moff
moff

Reputation: 6503

What about using the Cookie plugin for jQuery?

$.cookie('the_cookie', 'the_value'); // Create a session cookie ("the_cookie") and set its value to "the_value"
$.cookie('chocolate_chip_cookie', 'the_value', { // create a cookie with all available options
    expires: 7, // expires in seven days
    path: '/', // accessible from the whole site...
    domain: 'jquery.com',
    secure: true // ...but only on a secure connection
});
$.cookie('the_cookie', null); // delete the session cookie

Upvotes: 8

Related Questions