0

How can I make JavaScript (or jQuery) code only execute on the visitor's first visit and never again until a cookie expires or is removed?

For example: $('#example').hide(); How can I prevent this code from executing for 7 days for this visitor?

Odyssey
  • 263
  • 1
  • 2
  • 6

2 Answers2

2

try this tut: http://www.electrictoolbox.com/jquery-cookies/ set a cookie on first visit, read it out on any subsequent visit and do something like:

if($.cookie.isset() == true) {
    // do something
}
giorgio
  • 10,111
  • 2
  • 28
  • 41
0

In order to do like this. you should use server scripting for additional help.

Eg. in PHP

<?php
    if(isset($_SESSION['session_name'])){
     ?>
          Your javascript or jquery code here
     <?

    }

?>
dinesh
  • 827
  • 10
  • 15