Hide div using cookie if page has been already loaded once today?

Discussion in 'JavaScript' started by Error404, Apr 24, 2009.

  1. #1
    Hi,
    First, I am absolute javascipt newbie so please threat me like that.. :)))

    I need the following functionality to my webpage:

    Let's say I have a div with some unique ID on my page.
    Now, what I need is to show this div on my page only the first time visitor opens a page, and then not show it every next time he/she opens it for next 24h.

    So I need to set a cookie that hides div from page if it has already been shown to visitor, for next 24h, so that the content of this div will be shown to each unique visitor only once for a day.

    Thanks in advance... ;)

    Nikola
     
    Error404, Apr 24, 2009 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You might wanna look to serverside scripting for that - it's very easy to do in PHP, for instance.

    All you would have to do there is set the cookie, and then later check if the cookie exist:
    if (isset($_COOKIE['hidediv'])) {}
    else { echo "<div>something here</div>";}
     
    PoPSiCLe, Apr 25, 2009 IP
  3. JavaScriptBank.com

    JavaScriptBank.com Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cookie also is very easy to use, view source code of script below to solve your problem

    - Only Popup Once
     
    JavaScriptBank.com, Apr 27, 2009 IP