Web Analytics Made Easy -
StatCounter Pop up with javascript cookies. - CodingForum

Announcement

Collapse
No announcement yet.

Pop up with javascript cookies.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pop up with javascript cookies.

    I found this code here Edit fiddle - JSFiddle it works fine on the site but when I put it on my site the close will not work. Would anyone know why. Thanks
    Code:
    <script type="text/javascript">
    
    $(document).ready(function() {
    
      // If the 'hide cookie is not set we show the message
      if (!readCookie('hide')) {
        $('#popupDiv').show();
      }
    
      // Add the event that closes the popup and sets the cookie that tells us to
      // not show it again until one day has passed.
      $('#close').click(function() {
        $('#popupDiv').hide();
        createCookie('hide', true, 1)
        return false;
      });
    
    });
    
    // ---
    // And some generic cookie logic
    // ---
    function createCookie(name,value,days) {
      if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i < 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) {
      createCookie(name,"",-1);
    }
    </script>
    <div id="popupDiv">poup with stuff in it
    <a href="JavaScript:void(0)" id="close">close</a>
    </div>

    Code:
    	
    #popupDiv {
    display: inline-block;
    color:#000 !important;
    -webkit-border-radius:  5px 5px 5px 5px;
    -moz-border-radius: 5px 5px 5px 5px !important ;
    border-radius: 5px 5px 5px 5px;
    background-color:rgba(100%,100%,100%,1) !important;
    border-width: 1px !important;
    border-color: rgba( 0, 20, 45, .5) !important;
    border-style: solid !important;
    color: rgba( 0%,0%,0%,1) !important;
    box-shadow: 2px 2px 2px rgba(0%,0%,0%,0.2) !important;
    height: 135px;
    bottom: 10px;
    left: 0;
    margin: auto;
    padding: 5px 0px 1px 5px;
    position: absolute;
    right: 0;
    padding-top:5px;
    width: 740px;
    }

  • #2
    This:
    PHP Code:
      // If the hide cookie is not set we show the message
      
    if (!readCookie('hide')) {
        $(
    '#popupDiv').show();
      }... 
    seems to have incomplete hide / show logic. Try further to define this:
    PHP Code:
     // else if the hide cookie is SET we HIDE the message... 
    Hendra
    Last edited by hdewantara; Sep 11, 2016, 06:15 AM.

    Comment

    Working...
    X