title: Using Session storage to store whether a popup has been shown
body: <p>I have a website with a popup I built using plain HTML, CSS, and JS. Nothing fancy. I choose to display my popup after 15 seconds. Because I don't want to show the popup to anyone who's already seen it, I want to use session storage to store the fact I've displayed the popup.</p>
  <p>I came up with this code:</p>
  
  <pre><code>setTimeout(function() {
      var today = new Date();
      var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
      if (sessionStorage[mm+&quot;_displayed&quot;] != 'y'){
        var modal = document.getElementById(&quot;myModal&quot;);
        modal.style.display = &quot;block&quot;;
        sessionStorage[mm+&quot;_displayed&quot;] = 'y';
      }
    }, 15000);
  </code></pre>
  <p>The popup shows up after 15 seconds as expected. I can also see the session storage value in Chrome's Developer Tools. However I sometimes notice that the popup comes back up again.</p>
  <ul>
  <li>Is my comparison wrong?</li>
  <li>Is session storage specific to each tab? So far that's what I found but it seems counterintuitive. Sessions are shared across tabs so why wouldn't session storage be?</li>
  <li>Is local storage still &quot;live forever&quot;? I found a great <a href="https://www.sohamkamani.com/blog/javascript-localstorage-with-ttl-expiry/" rel="nofollow noreferrer">post on the topic and a workaround</a>.</li>
  </ul>
  <p>Thanks</p>