I want to have the div #topmessage slide down on the users second visit to the site. Also when the user clicks the #close the message will not be shown again. I guess I have to set a cookie and count it but not sure how. I have the following cookie plugin installed together with jquery http://plugins.jquery.com/files/jquery.cookie.js.txt
<script type="text/javascript">
jQuery(function($){
$('#topmessage').delay(1000).slideDown(400);
$("#close").click(function(){
$("#topmessage").slideToggle(400);
});
});
</script>
<div id="topmessage">
<a href="#" class="close" id="close">Close</a>
Hi welcome back, if you have any questions please feel free to <a href="/contact">contact me</a>.
</div>
Update: The reason I want to do this is to push the div to users who have visited the site once and are now returning on another date. I don’t just want to show the div the second time the site is loaded, but it has to be on another date or session as well. As far as I can see there is no way to access the creation date of a cookie?
This should work:
If you want to update the date in the cookie at each visit:
Working demo at: http://jsfiddle.net/roberkules/NL9jd/
UPDATE
added expiration date and path to cookie
added 2nd cookie just for the session