1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

On page load, if cookie set then hide div?

Discussion in 'JavaScript' started by Error404, Jun 15, 2009.

  1. #1
    Hi there,

    I'm not very good with Javascript so I need you help for page on my website...

    Basically what I need to do is to make a DIV shown only first time someone visits page, and then when he/she revisit it I want that same DIV hidden, and I want it hidden for next 24 hours... so in that way DIV would be shown only once a day, and only on first page load.

    So to make that happen I need to do fallowing, and I would need your help for that: I need a script that on a page load checks if cookie (which is 24h cookie) is set, if it is then it should hide that DIV, if it is not set then it should set it, so that DIV would be hidden on next page load...

    Can someone help me with this, cause I am getting mad trying to do this whole day...

    Thanks people!
     
    Error404, Jun 15, 2009 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    The following code check whether a cookie with a specified name is available.
    If available, then it hides a div.
    If not, then it creates a new cookie with expiry period as 1 day.



    Hope this code helps. :)
     
    Unni krishnan, Jun 15, 2009 IP
    Error404 likes this.
  3. Error404

    Error404 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey Unni, tnx...
    but for some reason this wont work in my case...

    as you can see:
    www.topfm.rs/index_lightbox1.html

    as you can see the div I want to hide is pop up banner, but it shows every time...
    you can view the source code and you'll see it's the same script you gave me..

    But now look: if instead of



    <div id ="autoload">
    <a href="images/index_open.jpg" rel="lightbox" id="img"></a>
    </div>
    Code (markup):
    I put something like


    <div id ="autoload">
    Some Text
    </div>
    Code (markup):
    IT WORKS!! It hides that text!

    So I guess the problem is in

    <a href="images/index_open.jpg" rel="lightbox" id="img"></a>
    Code (markup):
    which refuse to hide somehow!!...

    and you realize that I have this link/banner set to autorun on page load trough javascript so that when page loads this link (images/index_open.jpg) opens automatically..

    Can you help?
     
    Error404, Jun 15, 2009 IP
  4. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Hi ,

    Try adding ,

    instead of just,

    Hope this helps.
     
    Unni krishnan, Jun 15, 2009 IP