title: One time initialization for JavaScript variable
body: <p>I am developing a JavaScript for a webpage. This script has to create a popup, when the user is idle for a certain time. When the popup shows up, the user can choose to either close the popup or to minimize it.</p>
  
  <p>In case of closing the popup, further opened pages within the website shall not open the popup anymore. In case of minimizing, it should not do either. Nonetheless when the user has a certain idle time on any page the first time, it shall appear. </p>
  
  <p>It works in so far, that the pop up is created and also the closing of the pop works (and that it does not open anymore). But it does not work a refresh of the page anymore. So the storing does not work. And I know it is, because of my variables and a refresh also restarts the script again, so the initialization of the variables does rewrite the session value.</p>
  
  <p>So basically my question is: How do it do the 1st time initialization of the variables, which than are furtherly used after a refresh?</p>
  
  <p>My code is the following:</p>
  
  <pre><code>var isClosed = new Boolean(false);
  var isShrinked = new Boolean(false);
  var test = "Tesst";
  sessionStorage.setItem("session", isClosed=false);
  
  function close_popup() {
       $('#' + 'box').fadeOut('slow');
       sessionStorage.setItem("session", isClosed=true);
  }
  
  (function idelor(){
  
  document.onclick = document.onmousemove = document.onkeypress = function() {
      idleCounter = 0;
  };
  
  window.setInterval(function() {
      if (sessionStorage.getItem("session").toString() == "false") {
          if (isShrinked == false) {
              if (++idleCounter &gt;= IDLE_TIMEOUT) {
                  var scriptCode = document.createElement('p');
                  scriptCode.id = 'Sentotal';
                  document.getElementsByTagName('body')[0]
                          .appendChild(scriptCode);
                  document.getElementById("Sentotal").innerHTML = boxTotal;
              }
          }
      }
  }, interval);}());
  </code></pre>