javascript - Display div content only once in hour -
is possible show div in header of page visitor once in hour?
i want show bar shows visitor whether we're open or closed. 'visitor a' should see @ every first page loads , on next page not. in 30 minutes should shown him again.
i'm running jquery 1.10.2 @ website.
thank ideas
you can use cookies, set cookie lasts hour, , code make checks :
- if cookie not exist, display
div
, create cookie , make last hour - if cooie does exist, nothing
i don't think can handle cookies jquery directly, there plugins out there though. or, can use server side programming langage such php.
it depends on want show though. if it's ad or reminder (ex: take @ our xmas promotion) display @ every hour. in jquery script, check time, , if it's "round" hour (not sure how this) such 7:00, 8:00 or something, show div
, , hide after minute or whatever.
example php
<?php if(!isset($_cookie['yourcookie'])) { //set cookie setcookie("yourcookie", "open", time() + 3600); //expires in hour echo '<div class="open">we open!</div>'; } ?>
when reload page, cookie exist, div
not shown. after hour cookie deleted, next time user refreshes page shown, , cookie set again.
the downside of server-side solution unless user refreshes page after hour, won't shown after hour javascript.
edit have set cookie before outputting html, otherwise fail! make sure instruction set cookie before html in code.
Comments
Post a Comment