0

My pop just auto hides when loaded, even though there is no cookie set yet. i'm using the this Simple show/hide cookie , my console is not showing any errors. Am I leaving something out?

    <style>
    .notice {
      text-align: center;
      background-color: #fff;
      max-height: 100px; 
      left: 0px;
      right: 0px;
      color: #f5f5f5;
      display: none;
      z-index: 3008;
      width: 380px;
    }
    #text1, #text2 {
      position: relative;
    }
    </style>    

    <div id="barwrap" style="position:fixed;bottom:0;z-index:2;with:100%;height:100px;left:0;">
      <div class="notice">
          <div style="height: 40px; background-color: #f4a725;">
            <div style="text-align:center;">

            <h3 id="text1" style="padding-top: 6px;text-align:center;">Our Privacy Policy Has Changed. <a class="close" id="ok" href="#"><img style="width:20px; height: 20px;margin: 0 0 3px 15px;" src="/icon_privacy_exit.png"></a>
            </h3></div>

          </div>
          <div id="text2" style="height: 45px; color: #777;padding:6px 0 6px 0;font-size: 17px;clear:both;">You agree to the <a href="/privacy">Privacy Policy</a>.</div>
      </div>
    </div>  
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <script>
    $(document).ready(function() {

      if ($.cookie('notice') == 'closed') {
        $('.notice').hide();
      } else {
        $('.notice').show();
      }
        // Show or hide on load depending on cookie 

      $('.notice #ok').click(function(e) {
        e.preventDefault();
        $.cookie('notice','closed');
        $(this).parent().hide();
      });
        // close link to hide the notice until cookies are cleared

    });

    </script>
    <script>
        $(function(){setTimeout(function(){return
$(".notice").animate({height:"toggle"},"slow")},450);return
$("#ok").on("click",function(){
$("#barwrap").css("margin-bottom","0px");
$(".notice").animate({height:"toggle"},"slow");return!1})});
    </script>
acctman
  • 4,229
  • 30
  • 98
  • 142
  • what is the output of $.cookie('notice')? -- console.log($.cookie('notice')) – TehSphinX Jun 15 '16 at 10:25
  • Works fine for me: I open the page, the popup is there. I close the popup. Reload. No popup. And if I delete that cookie the popup is back. (Tested on Chrome 51 and Firefox 45) – yuriy636 Jun 15 '16 at 10:29
  • @TehSphinX I'm just getting an icon load error. I'm using Chrome – acctman Jun 15 '16 at 10:37
  • @yuriy636 I could not get it to work in chrome, but it did in Firefox and Safari. When I click the close button the box did not disappear only the top text. But, on reload the box was gone. – acctman Jun 15 '16 at 10:40
  • $.cookie('notice') == 'closed' is still true for some weird reason if $.cookie('notice') is not set. Maybe output that: console.log($.cookie('notice') == 'closed') – TehSphinX Jun 15 '16 at 10:40
  • Nevermind what I said about Chrome, I was testing it in a local server(127.0.0.1), if you load it from file(file://) it doesn't work(the popup still there as the cookie isn't set). Firefox works fine with file://, though. | More info: http://stackoverflow.com/a/347997/3499595 – yuriy636 Jun 15 '16 at 10:46
  • @yuriy636 thanks for helping me trouble shoot chrome. my other issue is that when the close icon is clicked it removes the first header line but does not close the box. Are my div's set wrong? – acctman Jun 15 '16 at 10:50
  • 2
    same here... the popup always shows as there is no cookie. (Cookie doesn't set because I didn't put it on a webserver.) But your problem is different. your popup is being hidden although there is no cookie. Meaning we cannot reproduce your issue. – TehSphinX Jun 15 '16 at 10:51
  • 1
    @acctman If you want to hide the entire `.notice` div, change `$(this).parent().hide();` to `$(this).parents('.notice').hide();` – yuriy636 Jun 15 '16 at 10:59
  • @yuriy636 thank you for all your help – acctman Jun 15 '16 at 11:08
  • @TehSphinX Thanks for helping me solve my issue – acctman Jun 15 '16 at 11:08

0 Answers0