title: How can I display a Javascript prompt once on website load?
body: <p>I have a javascript prompt that executes when I open my website for the first time. The basic function of this prompt is to ask the user for their name, and then insert it into a header I.E. "Hello, 'user'!" I have multiple pages on my website, and whenever I navigate to a different page and then navigate back to the home page, the prompt is displayed again, asking the user the same question over and over. Is there any way to have the prompt display only once on the first load of the website, and then keep the user's name in a variable until they close the website?</p>
  
  <p>Here is my javascript:</p>
  
  <pre class="lang-java prettyprint-override"><code>function askName() {
      let username = prompt("To make your time on this website better, please enter your name.");
      if (username != null) {
          document.getElementById("userpara").innerHTML = "Hello, " + username;
      } else {
          document.getElementById("noUser").innerHTML = "Welcome, Stranger!";
      }
  }
  </code></pre>
  
  <p>And here is my Html: </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;h1 id="userpara" style="text-align: center;"&gt;&lt;/h1&gt;
  &lt;h1 id="noUser" style="text-align: center;"&gt;&lt;/h1&gt;
  </code></pre>
  
  <p>To execute the function on page load, I used the <code>onload</code> function in the body tag in html like this: </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;body onload="askname()"&gt;
  ...
  &lt;/body&gt;
  </code></pre>
  
  <p>Feel free to correct me on any of my code as well, since I'm still learning :)</p>