0

i need to add cookies to my modal popup to be visible only once for user per browser session in all project web pages.

here is the HTML Code

    <div id="popup">
    <div class="modalconent">

      <button id="button"><span class="close">&times;</span></button>

         <h1></h1>

        <p>Some text in the Modal..</p>
    </div>
</div> 

and here is my javascript code:

window.onload = function () {
  document.getElementById('button').onclick = function () {
      document.getElementById('popup').style.display = "none"
  };
};

and here is my css code:

#modal {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 99999;
    height: 100%;
    width: 100%;
}
.modalconent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    width: 80%;
    padding: 20px;
}
yasser Eltibili
  • 134
  • 2
  • 8
  • 2
    a) you should hide the modal by default, and show it if the cookie doesn't exist, not the other way around b) there's zero JS code dealing with cookies; please do appropriate research first, then add the code you've tried to your question in case you get stuck and tell us exactly how it failed. –  Sep 18 '20 at 16:24
  • Does this answer your question? [How do I create and read a value from cookie?](https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) – devlin carnate Sep 18 '20 at 16:27
  • https://stackoverflow.com/questions/55477813/display-a-modal-after-x-pages-views-with-js-cookie – Code Assassin Dec 16 '22 at 06:56

0 Answers0