How to use cookies in JavaScript to remember if user has clicked 'don't show me this again' -


i have created pop dialog box prompts users either visit our facebook, twitter or click 'don't show me again'

i implementing short period of time doesn't become annoying, don't want pop every time refresh page.

i have looked @ cookies javascript can't seem work code.

my js code looks this:

    function popup(div){ document.getelementbyid(div).style.display='block'; return false; } function hide(div){ document.getelementbyid(div).style.display='none'; return false; } 

and html looks this:

<body onload="return popup('pop')">      <div id="pop" class="disablebackground">         <div id="popup">         <h1 title="social">you can find here</h1>         <div class="arrow-down"></div>         <br />         <a class="btn-connect-option facebook badge-facebook-connect" href="http://facebook.com" target="_blank">facebook</a>         <a class="btn-connect-option twitter" href="http://twitter.com/" target="_blank">twitter</a>         <div class="clear"></div>         <p onclick="return hide('pop')" style="cursor: pointer">don't show me again</p>         </div>         </div> 

i not expecting code needs, appreciate guidance on how achieve this.

thanks lot!

if search answers in tag contain getcookie , setcookie there enough results build our functions:

enter image description here

<html> <head> <script>     var our_cookie_name = 'popupdiv';     function popup( div ) {         if( getcookie( our_cookie_name ) != div )             document.getelementbyid(div).style.display='block';         return false;     }     function hide( div ) {         setcookie( our_cookie_name, div );         document.getelementbyid(div).style.display='none';         return false;     }     function setcookie( name, value, days ) {         var expires = "";         if ( days ) {             var date = new date();              date.settime( date.gettime() + (days*24*60*60*1000) );             var expires = "; expires=" + date.togmtstring();         }         document.cookie = name + "="+value+expires+"; path=/";     }      function getcookie( name ) {         var nameeq = name + "=";         var ca = document.cookie.split(";");         for( var i=0; < ca.length; i++ ) {             var c = ca[i];              while ( c.charat(0) == ' ' )                  c = c.substring(1,c.length);             if ( c.indexof(nameeq) == 0 )                  return c.substring( nameeq.length, c.length );         }         return null;     }     function erasecookie( name ) {         setcookie( name, "", -1 );     } </script> </head> <body onload="popup('popup-container')"> <small><a href="javascript:erasecookie(our_cookie_name)">clear cookie</a></small> <hr /> <div id="popup-container" class="disablebackground" style="display:none">     <div id="popup">         <h1 title="social">you can find here</h1>         <div class="arrow-down"></div>         <br />         <a class="btn-connect-option facebook badge-facebook-connect" href="http://facebook.com" target="_blank">facebook</a>         <a class="btn-connect-option twitter" href="http://twitter.com/" target="_blank">twitter</a>         <div class="clear"></div>         <p onclick="return hide('popup-container')" style="cursor: pointer">don't show me again</p>     </div> </div> </body> </html> 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -