Skip to content Skip to sidebar Skip to footer

Javascript/jquery Only Gets Executed On First Visit, Cookie Prevents It From Executing Again

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 ca

Solution 1:

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
}

Solution 2:

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

Eg. in PHP

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

    }

?>

Post a Comment for "Javascript/jquery Only Gets Executed On First Visit, Cookie Prevents It From Executing Again"