age verification pop up on not getting existing cookie












1















I have a age verification pop up when a user visits the site for the first time. I want to box to pop up when going to the site for the first time and not ask again unless closing out the browser and going back to the site. So far it works like it should, pop ups and creates the cookie. It isn't recognizing the cookie though when I visit other pages on the site and continues to pop up.






function getBaseUrl(){return window.location.protocol+"//"+window.location.host}function getTemplate(e){var n=getBaseUrl()+handlebarTemplatesPath+e+".hbs";return jQuery.get(n).then(function(e){return Handlebars.compile(e)})}var handlebarTemplatesPath="/templates/components/common/";addAgeVerifyToBody=function(){getTemplate("age-verify").done(function(e){jQuery("body").append(e)})},jQuery(document).ready(function(){"true"!=Cookies.get("age-verified")&&addAgeVerifyToBody()}),overAge=function(){jQuery("#age-verify").addClass("hidden"),Cookies.set("age-verified","true")},underAge=function(){jQuery("#age-verify").addClass("under")},goBack=function(){window.history.back()};    

#age-verify {
position: fixed;
z-index: 9997;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
transition: 500ms;
}
#age-verify .window {
position: absolute;
z-index: 9998;
top: 50%;
left: 50%;
width: 400px;
height: 250px;
overflow: hidden;
padding: 40px;
margin-left: -200px;
margin-top: -125px;
background-color: #fff;
border: 6px solid Red;
box-sizing: border-box;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
transition: 500ms;
}
#age-verify .window span {
display: block;
text-align: center;
margin-bottom: 10px;
font-family: "Open Sans", sans-serif;
font-size: 17px;
}
#age-verify .window span.title {
color: Red;
font-size: 24px;
}
#age-verify .window button {
border: 0;
margin: 0;
padding: 0;
width: 48%;
height: 60px;
color: #FFF;
font-size: 18px;
background-color: Red;
margin-top: 20px;
font-family: "Open Sans", sans-serif;
transform: scale(1);
transition: .2s;
}
#age-verify .window button.back {
display: block;
float: none;
margin: auto;
background-color: #fff;
color: Red !important;
margin-top: 20px;
}
#age-verify .window button.yes {
float: left;
}
#age-verify .window button.no {
float: right;
}
#age-verify .window button:hover {
transform: scale(1.1);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
background-color: #ff3333;
}
#age-verify .window .underBox {
position: absolute;
width: 400px;
height: 250px;
padding: 40px;
top: 100%;
left: 0;
right: 0;
background-color: Red;
transition: 500ms;
box-sizing: border-box;
}
#age-verify .window .underBox * {
color: #FFF !important;
}
#age-verify.hidden {
opacity: 0;
visibility: hidden;
}
#age-verify.hidden .window {
transform: scale(0.5);
}
#age-verify.under .window .underBox {
top: 0%;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
<div id="age-verify">
<div class="window">
<span class="title">Are you over 21?</span>
<span>To visit our website, you must be of legal drinking age.</span>
<button class="yes" onclick="overAge()">Yes</button>
<button class="no" onclick="underAge()">No</button>
<div class="underBox">
<span class="title">Sorry!</span>
<span>You need to be at least 21 to visit our website.</span>
<button class="back" onclick="goBack()">Go Back</button>
</div>
</div>
</div>












share|improve this question



























    1















    I have a age verification pop up when a user visits the site for the first time. I want to box to pop up when going to the site for the first time and not ask again unless closing out the browser and going back to the site. So far it works like it should, pop ups and creates the cookie. It isn't recognizing the cookie though when I visit other pages on the site and continues to pop up.






    function getBaseUrl(){return window.location.protocol+"//"+window.location.host}function getTemplate(e){var n=getBaseUrl()+handlebarTemplatesPath+e+".hbs";return jQuery.get(n).then(function(e){return Handlebars.compile(e)})}var handlebarTemplatesPath="/templates/components/common/";addAgeVerifyToBody=function(){getTemplate("age-verify").done(function(e){jQuery("body").append(e)})},jQuery(document).ready(function(){"true"!=Cookies.get("age-verified")&&addAgeVerifyToBody()}),overAge=function(){jQuery("#age-verify").addClass("hidden"),Cookies.set("age-verified","true")},underAge=function(){jQuery("#age-verify").addClass("under")},goBack=function(){window.history.back()};    

    #age-verify {
    position: fixed;
    z-index: 9997;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    transition: 500ms;
    }
    #age-verify .window {
    position: absolute;
    z-index: 9998;
    top: 50%;
    left: 50%;
    width: 400px;
    height: 250px;
    overflow: hidden;
    padding: 40px;
    margin-left: -200px;
    margin-top: -125px;
    background-color: #fff;
    border: 6px solid Red;
    box-sizing: border-box;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transition: 500ms;
    }
    #age-verify .window span {
    display: block;
    text-align: center;
    margin-bottom: 10px;
    font-family: "Open Sans", sans-serif;
    font-size: 17px;
    }
    #age-verify .window span.title {
    color: Red;
    font-size: 24px;
    }
    #age-verify .window button {
    border: 0;
    margin: 0;
    padding: 0;
    width: 48%;
    height: 60px;
    color: #FFF;
    font-size: 18px;
    background-color: Red;
    margin-top: 20px;
    font-family: "Open Sans", sans-serif;
    transform: scale(1);
    transition: .2s;
    }
    #age-verify .window button.back {
    display: block;
    float: none;
    margin: auto;
    background-color: #fff;
    color: Red !important;
    margin-top: 20px;
    }
    #age-verify .window button.yes {
    float: left;
    }
    #age-verify .window button.no {
    float: right;
    }
    #age-verify .window button:hover {
    transform: scale(1.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    background-color: #ff3333;
    }
    #age-verify .window .underBox {
    position: absolute;
    width: 400px;
    height: 250px;
    padding: 40px;
    top: 100%;
    left: 0;
    right: 0;
    background-color: Red;
    transition: 500ms;
    box-sizing: border-box;
    }
    #age-verify .window .underBox * {
    color: #FFF !important;
    }
    #age-verify.hidden {
    opacity: 0;
    visibility: hidden;
    }
    #age-verify.hidden .window {
    transform: scale(0.5);
    }
    #age-verify.under .window .underBox {
    top: 0%;
    }

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
    <div id="age-verify">
    <div class="window">
    <span class="title">Are you over 21?</span>
    <span>To visit our website, you must be of legal drinking age.</span>
    <button class="yes" onclick="overAge()">Yes</button>
    <button class="no" onclick="underAge()">No</button>
    <div class="underBox">
    <span class="title">Sorry!</span>
    <span>You need to be at least 21 to visit our website.</span>
    <button class="back" onclick="goBack()">Go Back</button>
    </div>
    </div>
    </div>












    share|improve this question

























      1












      1








      1








      I have a age verification pop up when a user visits the site for the first time. I want to box to pop up when going to the site for the first time and not ask again unless closing out the browser and going back to the site. So far it works like it should, pop ups and creates the cookie. It isn't recognizing the cookie though when I visit other pages on the site and continues to pop up.






      function getBaseUrl(){return window.location.protocol+"//"+window.location.host}function getTemplate(e){var n=getBaseUrl()+handlebarTemplatesPath+e+".hbs";return jQuery.get(n).then(function(e){return Handlebars.compile(e)})}var handlebarTemplatesPath="/templates/components/common/";addAgeVerifyToBody=function(){getTemplate("age-verify").done(function(e){jQuery("body").append(e)})},jQuery(document).ready(function(){"true"!=Cookies.get("age-verified")&&addAgeVerifyToBody()}),overAge=function(){jQuery("#age-verify").addClass("hidden"),Cookies.set("age-verified","true")},underAge=function(){jQuery("#age-verify").addClass("under")},goBack=function(){window.history.back()};    

      #age-verify {
      position: fixed;
      z-index: 9997;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.8);
      transition: 500ms;
      }
      #age-verify .window {
      position: absolute;
      z-index: 9998;
      top: 50%;
      left: 50%;
      width: 400px;
      height: 250px;
      overflow: hidden;
      padding: 40px;
      margin-left: -200px;
      margin-top: -125px;
      background-color: #fff;
      border: 6px solid Red;
      box-sizing: border-box;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      transition: 500ms;
      }
      #age-verify .window span {
      display: block;
      text-align: center;
      margin-bottom: 10px;
      font-family: "Open Sans", sans-serif;
      font-size: 17px;
      }
      #age-verify .window span.title {
      color: Red;
      font-size: 24px;
      }
      #age-verify .window button {
      border: 0;
      margin: 0;
      padding: 0;
      width: 48%;
      height: 60px;
      color: #FFF;
      font-size: 18px;
      background-color: Red;
      margin-top: 20px;
      font-family: "Open Sans", sans-serif;
      transform: scale(1);
      transition: .2s;
      }
      #age-verify .window button.back {
      display: block;
      float: none;
      margin: auto;
      background-color: #fff;
      color: Red !important;
      margin-top: 20px;
      }
      #age-verify .window button.yes {
      float: left;
      }
      #age-verify .window button.no {
      float: right;
      }
      #age-verify .window button:hover {
      transform: scale(1.1);
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      background-color: #ff3333;
      }
      #age-verify .window .underBox {
      position: absolute;
      width: 400px;
      height: 250px;
      padding: 40px;
      top: 100%;
      left: 0;
      right: 0;
      background-color: Red;
      transition: 500ms;
      box-sizing: border-box;
      }
      #age-verify .window .underBox * {
      color: #FFF !important;
      }
      #age-verify.hidden {
      opacity: 0;
      visibility: hidden;
      }
      #age-verify.hidden .window {
      transform: scale(0.5);
      }
      #age-verify.under .window .underBox {
      top: 0%;
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
      <div id="age-verify">
      <div class="window">
      <span class="title">Are you over 21?</span>
      <span>To visit our website, you must be of legal drinking age.</span>
      <button class="yes" onclick="overAge()">Yes</button>
      <button class="no" onclick="underAge()">No</button>
      <div class="underBox">
      <span class="title">Sorry!</span>
      <span>You need to be at least 21 to visit our website.</span>
      <button class="back" onclick="goBack()">Go Back</button>
      </div>
      </div>
      </div>












      share|improve this question














      I have a age verification pop up when a user visits the site for the first time. I want to box to pop up when going to the site for the first time and not ask again unless closing out the browser and going back to the site. So far it works like it should, pop ups and creates the cookie. It isn't recognizing the cookie though when I visit other pages on the site and continues to pop up.






      function getBaseUrl(){return window.location.protocol+"//"+window.location.host}function getTemplate(e){var n=getBaseUrl()+handlebarTemplatesPath+e+".hbs";return jQuery.get(n).then(function(e){return Handlebars.compile(e)})}var handlebarTemplatesPath="/templates/components/common/";addAgeVerifyToBody=function(){getTemplate("age-verify").done(function(e){jQuery("body").append(e)})},jQuery(document).ready(function(){"true"!=Cookies.get("age-verified")&&addAgeVerifyToBody()}),overAge=function(){jQuery("#age-verify").addClass("hidden"),Cookies.set("age-verified","true")},underAge=function(){jQuery("#age-verify").addClass("under")},goBack=function(){window.history.back()};    

      #age-verify {
      position: fixed;
      z-index: 9997;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.8);
      transition: 500ms;
      }
      #age-verify .window {
      position: absolute;
      z-index: 9998;
      top: 50%;
      left: 50%;
      width: 400px;
      height: 250px;
      overflow: hidden;
      padding: 40px;
      margin-left: -200px;
      margin-top: -125px;
      background-color: #fff;
      border: 6px solid Red;
      box-sizing: border-box;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      transition: 500ms;
      }
      #age-verify .window span {
      display: block;
      text-align: center;
      margin-bottom: 10px;
      font-family: "Open Sans", sans-serif;
      font-size: 17px;
      }
      #age-verify .window span.title {
      color: Red;
      font-size: 24px;
      }
      #age-verify .window button {
      border: 0;
      margin: 0;
      padding: 0;
      width: 48%;
      height: 60px;
      color: #FFF;
      font-size: 18px;
      background-color: Red;
      margin-top: 20px;
      font-family: "Open Sans", sans-serif;
      transform: scale(1);
      transition: .2s;
      }
      #age-verify .window button.back {
      display: block;
      float: none;
      margin: auto;
      background-color: #fff;
      color: Red !important;
      margin-top: 20px;
      }
      #age-verify .window button.yes {
      float: left;
      }
      #age-verify .window button.no {
      float: right;
      }
      #age-verify .window button:hover {
      transform: scale(1.1);
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      background-color: #ff3333;
      }
      #age-verify .window .underBox {
      position: absolute;
      width: 400px;
      height: 250px;
      padding: 40px;
      top: 100%;
      left: 0;
      right: 0;
      background-color: Red;
      transition: 500ms;
      box-sizing: border-box;
      }
      #age-verify .window .underBox * {
      color: #FFF !important;
      }
      #age-verify.hidden {
      opacity: 0;
      visibility: hidden;
      }
      #age-verify.hidden .window {
      transform: scale(0.5);
      }
      #age-verify.under .window .underBox {
      top: 0%;
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
      <div id="age-verify">
      <div class="window">
      <span class="title">Are you over 21?</span>
      <span>To visit our website, you must be of legal drinking age.</span>
      <button class="yes" onclick="overAge()">Yes</button>
      <button class="no" onclick="underAge()">No</button>
      <div class="underBox">
      <span class="title">Sorry!</span>
      <span>You need to be at least 21 to visit our website.</span>
      <button class="back" onclick="goBack()">Go Back</button>
      </div>
      </div>
      </div>








      function getBaseUrl(){return window.location.protocol+"//"+window.location.host}function getTemplate(e){var n=getBaseUrl()+handlebarTemplatesPath+e+".hbs";return jQuery.get(n).then(function(e){return Handlebars.compile(e)})}var handlebarTemplatesPath="/templates/components/common/";addAgeVerifyToBody=function(){getTemplate("age-verify").done(function(e){jQuery("body").append(e)})},jQuery(document).ready(function(){"true"!=Cookies.get("age-verified")&&addAgeVerifyToBody()}),overAge=function(){jQuery("#age-verify").addClass("hidden"),Cookies.set("age-verified","true")},underAge=function(){jQuery("#age-verify").addClass("under")},goBack=function(){window.history.back()};    

      #age-verify {
      position: fixed;
      z-index: 9997;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.8);
      transition: 500ms;
      }
      #age-verify .window {
      position: absolute;
      z-index: 9998;
      top: 50%;
      left: 50%;
      width: 400px;
      height: 250px;
      overflow: hidden;
      padding: 40px;
      margin-left: -200px;
      margin-top: -125px;
      background-color: #fff;
      border: 6px solid Red;
      box-sizing: border-box;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      transition: 500ms;
      }
      #age-verify .window span {
      display: block;
      text-align: center;
      margin-bottom: 10px;
      font-family: "Open Sans", sans-serif;
      font-size: 17px;
      }
      #age-verify .window span.title {
      color: Red;
      font-size: 24px;
      }
      #age-verify .window button {
      border: 0;
      margin: 0;
      padding: 0;
      width: 48%;
      height: 60px;
      color: #FFF;
      font-size: 18px;
      background-color: Red;
      margin-top: 20px;
      font-family: "Open Sans", sans-serif;
      transform: scale(1);
      transition: .2s;
      }
      #age-verify .window button.back {
      display: block;
      float: none;
      margin: auto;
      background-color: #fff;
      color: Red !important;
      margin-top: 20px;
      }
      #age-verify .window button.yes {
      float: left;
      }
      #age-verify .window button.no {
      float: right;
      }
      #age-verify .window button:hover {
      transform: scale(1.1);
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      background-color: #ff3333;
      }
      #age-verify .window .underBox {
      position: absolute;
      width: 400px;
      height: 250px;
      padding: 40px;
      top: 100%;
      left: 0;
      right: 0;
      background-color: Red;
      transition: 500ms;
      box-sizing: border-box;
      }
      #age-verify .window .underBox * {
      color: #FFF !important;
      }
      #age-verify.hidden {
      opacity: 0;
      visibility: hidden;
      }
      #age-verify.hidden .window {
      transform: scale(0.5);
      }
      #age-verify.under .window .underBox {
      top: 0%;
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
      <div id="age-verify">
      <div class="window">
      <span class="title">Are you over 21?</span>
      <span>To visit our website, you must be of legal drinking age.</span>
      <button class="yes" onclick="overAge()">Yes</button>
      <button class="no" onclick="underAge()">No</button>
      <div class="underBox">
      <span class="title">Sorry!</span>
      <span>You need to be at least 21 to visit our website.</span>
      <button class="back" onclick="goBack()">Go Back</button>
      </div>
      </div>
      </div>





      function getBaseUrl(){return window.location.protocol+"//"+window.location.host}function getTemplate(e){var n=getBaseUrl()+handlebarTemplatesPath+e+".hbs";return jQuery.get(n).then(function(e){return Handlebars.compile(e)})}var handlebarTemplatesPath="/templates/components/common/";addAgeVerifyToBody=function(){getTemplate("age-verify").done(function(e){jQuery("body").append(e)})},jQuery(document).ready(function(){"true"!=Cookies.get("age-verified")&&addAgeVerifyToBody()}),overAge=function(){jQuery("#age-verify").addClass("hidden"),Cookies.set("age-verified","true")},underAge=function(){jQuery("#age-verify").addClass("under")},goBack=function(){window.history.back()};    

      #age-verify {
      position: fixed;
      z-index: 9997;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.8);
      transition: 500ms;
      }
      #age-verify .window {
      position: absolute;
      z-index: 9998;
      top: 50%;
      left: 50%;
      width: 400px;
      height: 250px;
      overflow: hidden;
      padding: 40px;
      margin-left: -200px;
      margin-top: -125px;
      background-color: #fff;
      border: 6px solid Red;
      box-sizing: border-box;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      transition: 500ms;
      }
      #age-verify .window span {
      display: block;
      text-align: center;
      margin-bottom: 10px;
      font-family: "Open Sans", sans-serif;
      font-size: 17px;
      }
      #age-verify .window span.title {
      color: Red;
      font-size: 24px;
      }
      #age-verify .window button {
      border: 0;
      margin: 0;
      padding: 0;
      width: 48%;
      height: 60px;
      color: #FFF;
      font-size: 18px;
      background-color: Red;
      margin-top: 20px;
      font-family: "Open Sans", sans-serif;
      transform: scale(1);
      transition: .2s;
      }
      #age-verify .window button.back {
      display: block;
      float: none;
      margin: auto;
      background-color: #fff;
      color: Red !important;
      margin-top: 20px;
      }
      #age-verify .window button.yes {
      float: left;
      }
      #age-verify .window button.no {
      float: right;
      }
      #age-verify .window button:hover {
      transform: scale(1.1);
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      background-color: #ff3333;
      }
      #age-verify .window .underBox {
      position: absolute;
      width: 400px;
      height: 250px;
      padding: 40px;
      top: 100%;
      left: 0;
      right: 0;
      background-color: Red;
      transition: 500ms;
      box-sizing: border-box;
      }
      #age-verify .window .underBox * {
      color: #FFF !important;
      }
      #age-verify.hidden {
      opacity: 0;
      visibility: hidden;
      }
      #age-verify.hidden .window {
      transform: scale(0.5);
      }
      #age-verify.under .window .underBox {
      top: 0%;
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.min.js"></script>
      <div id="age-verify">
      <div class="window">
      <span class="title">Are you over 21?</span>
      <span>To visit our website, you must be of legal drinking age.</span>
      <button class="yes" onclick="overAge()">Yes</button>
      <button class="no" onclick="underAge()">No</button>
      <div class="underBox">
      <span class="title">Sorry!</span>
      <span>You need to be at least 21 to visit our website.</span>
      <button class="back" onclick="goBack()">Go Back</button>
      </div>
      </div>
      </div>






      javascript jquery html cookies handlebars.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 '18 at 17:46









      lostInTheTetonslostInTheTetons

      707618




      707618
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Try something like this:






              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>








          share|improve this answer
























          • works great thank you!

            – lostInTheTetons
            Nov 18 '18 at 20:41











          • Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

            – lostInTheTetons
            Nov 22 '18 at 1:04











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53363791%2fage-verification-pop-up-on-not-getting-existing-cookie%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Try something like this:






              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>








          share|improve this answer
























          • works great thank you!

            – lostInTheTetons
            Nov 18 '18 at 20:41











          • Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

            – lostInTheTetons
            Nov 22 '18 at 1:04
















          1














          Try something like this:






              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>








          share|improve this answer
























          • works great thank you!

            – lostInTheTetons
            Nov 18 '18 at 20:41











          • Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

            – lostInTheTetons
            Nov 22 '18 at 1:04














          1












          1








          1







          Try something like this:






              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>








          share|improve this answer













          Try something like this:






              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>








              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>





              $(document).ready(function(){

          window.onload = function() {
          checkCookie();
          };

          function getCookie(cname) {
          var name = cname + "=";
          var decodedCookie = decodeURIComponent(document.cookie);
          var ca = decodedCookie.split(';');
          for(var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
          c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
          }
          }
          return "";
          }
          function checkCookie() {
          var user=getCookie("age-verified");
          if (user != "") {
          $("#age-verify").addClass("hidden");
          }
          }


          var yesEl = document.getElementById('yes');
          var noEl = document.getElementById('no');

          yesEl.addEventListener('click', function(){
          //document.cookie = 'age-verified; expires=1';
          $('#age-verify').addClass('hidden');
          function setCookie(cname,cvalue,exdays) {
          var d = new Date();
          d.setTime(d.getTime() + (exdays*1));
          var expires = "expires=" + d.toGMTString();
          document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
          }
          });

          noEl.addEventListener('click', function() {
          $('#age-text').addClass('hiddenText');
          $('#under-age').removeClass('hiddenText');
          $('#yes').addClass('hiddenText');
          });

          });

          #age-verify {
          position: fixed;
          z-index: 9997;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(0, 0, 0, 0.8);
          }
          #age-verify .window {
          position: absolute;
          z-index: 9998;
          top: 50%;
          left: 50%;
          width: 400px;
          height: 250px;
          overflow: hidden;
          padding: 40px;
          margin-left: -200px;
          margin-top: -125px;
          background-color: #fff;
          border: 6px solid Red;
          box-sizing: border-box;
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          }
          #age-verify .window span {
          display: block;
          text-align: center;
          margin-bottom: 10px;
          font-family: "Open Sans", sans-serif;
          font-size: 17px;
          }
          #age-verify .window span.title {
          color: Red;
          font-size: 24px;
          }
          #age-verify .window button {
          border: 0;
          margin: 0;
          padding: 0;
          width: 48%;
          height: 60px;
          color: #FFF;
          font-size: 18px;
          background-color: Red;
          margin-top: 20px;
          font-family: "Open Sans", sans-serif;
          transform: scale(1);
          }
          #age-verify .window button.back {
          display: block;
          float: none;
          margin: auto;
          background-color: #fff;
          color: Red !important;
          margin-top: 20px;
          }
          #age-verify .window button.yes {
          float: left;
          }
          #age-verify .window button.no {
          float: right;
          }
          #age-verify .window button:hover {
          transform: scale(1.1);
          box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
          background-color: #ff3333;
          }
          #age-verify .window .underBox {
          position: absolute;
          width: 400px;
          height: 250px;
          padding: 40px;
          top: 100%;
          left: 0;
          right: 0;
          background-color: Red;
          transition: 500ms;
          box-sizing: border-box;
          }
          #age-verify .window .underBox * {
          color: #FFF !important;
          }
          #age-verify.hidden {
          opacity: 0;
          visibility: hidden;
          }
          #age-verify.hidden .window {
          transform: scale(0.5);
          }
          #age-verify.under .window .underBox {
          top: 0%;
          }
          .hiddenText {
          display: none;
          }

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" type="text/javascript"></script>
          <div id="age-verify">
          <div class="window">
          <div id="age-text">
          <span class="title">Are you over 21?</span>
          <span>You must be 21 to visit this website.</span>
          </div>
          <div id="under-age" class="hiddenText">
          <span class="title">Sorry!</span>
          <span>You need to be at least 21 to visit our website.</span>
          </div>
          <button id="yes" class="yes">Yes</button>
          <button id="no" class="no">No</button>
          </div>
          </div>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 '18 at 20:40









          JBaldwinJBaldwin

          199113




          199113













          • works great thank you!

            – lostInTheTetons
            Nov 18 '18 at 20:41











          • Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

            – lostInTheTetons
            Nov 22 '18 at 1:04



















          • works great thank you!

            – lostInTheTetons
            Nov 18 '18 at 20:41











          • Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

            – lostInTheTetons
            Nov 22 '18 at 1:04

















          works great thank you!

          – lostInTheTetons
          Nov 18 '18 at 20:41





          works great thank you!

          – lostInTheTetons
          Nov 18 '18 at 20:41













          Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

          – lostInTheTetons
          Nov 22 '18 at 1:04





          Doesn't seem to work anymore or just didn't catch it the first time.. It's not recognizing the cookie or something because it pops up on every page

          – lostInTheTetons
          Nov 22 '18 at 1:04




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53363791%2fage-verification-pop-up-on-not-getting-existing-cookie%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini