Pop up open once a day by user in javascript?

1

I'm creating my website, and I created a basic popup with html , css3 , javascript and would like to know how do I get the cookie of the user and display the popup only one instead on my site, follow the syntax below.

window.onload = function() {
  function fechar() {
    var popup = document.getElementById('popup');
    var cor = document.getElementById('cor');
    popup.style.display = "none";
    cor.style.display = "none";
  }
}
.popup {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 500px;
  height: 300px;
  padding: 15px;
  border: solid 1px black;
  background: url(https://www.google.com.br/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png) no-repeat;
  z-index: 2;
  display: none;
}
.popup p {
  position: relative;
  top: -30px;
  left: 0;
  color: white;
}
.popup p a {
  position: relative;
  top: 68px;
  left: 178px;
  text-decoration: none;
  color: black;
}
img[alt="fechar"] {
  height: 26px;
  width: 28px;
  position: relative;
  left: 454px;
  top: -14px;
}
<body>
  <div class="popup" id="popup">
    <a href="javascript:fechar()">
      <img src="img/fechar.png" alt="fechar">
    </a>
    <p>Inscreva-se em meu canal do youtube Leonardo Santos link abaixo</p>
    <p><a href="#" target="_blank">clique aqui</a>
    </p>
  </div>
    
asked by anonymous 03.12.2016 / 15:58

1 answer

1

You can create a data object:

d = new Date()

Then increase the date by one day:

d.setDate(d.getDate() + 1*24*60*60*1000)

And finally create a cookie that expires after one day:

document.cookie = "visto=true; expires=" + d.toUTCString() + ";path=/"

To find out if a day has passed, check that: document.cookie == null

To learn more see this example here

    
03.12.2016 / 16:21