Results 1 to 3 of 3

Thread: Cookie: Hide div on click 24hr?

  1. #1
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Cookie: Hide div on click 24hr?

    I would like a simple JavaScript code that will allow me to hide a certain div element when clicked for a predefined amount of time. To be a little more informative, I have a suggestions box that appears when the home page is loaded. What I would like is when the div close button is clicked it sets a cookie to keep the box div closed for 24 hours (1day). Simply said, when the div close button is pressed, the box div is hidden for 24 hours. Note: I have a javascript that allows the close button to close the box but it will load every refresh.

    http://i.stack.imgur.com/du1pA.jpg
    http://pastebin.com/rwZiu6ai
    Last edited by ComputerSolutions; 05-20-2012 at 04:03 PM.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function CheckCookie(nme){
     if (cookie(nme)){
      document.getElementById(nme).style.display='none';
     }
    }
    
    function setcookie(nme,days){
     document.cookie=nme+'=true;expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path=/';
     document.getElementById(nme).style.display='none';
    }
    
    function cookie(nme){
     var re=new RegExp(nme+'[^;]+','i');
     if (document.cookie.match(re)){
      return document.cookie.match(re)[0].split("=")[1];
     }
     return null;
    }
    
    
    /*]]>*/
    </script>
    </head>
    
    <body>
    <input type="button" name="" value="Hide" onmouseup="setcookie('nme',1)"/>
    <img id="nme" src="http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg" alt="img" />
    <script type="text/javascript">
    /*<![CDATA[*/
     CheckCookie('nme');
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •