title: Send data over to another html file
body: <p>I am trying to get certain data from my database on my (1) HTML page and display it on the (2) HTML page.</p>
  
  <p>My codes for (1) html file:</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
      &lt;script src="example.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      .
      .
      .
      &lt;button item="' + count + '" onclick="getData(this)"&gt;Example&lt;/button&gt;
      .
      .
      .
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>And the JS for it:</p>
  
  <pre><code>
          .
          .
          .
          var currentIndex = 0;
  
          //This function is to display the details of an individual item
          function getData(element) {
              var request = new XMLHttpRequest();
  
              request.open("GET", "/theroute", true);
              request.setRequestHeader("Content-Type", "application/json");
              request.onload = function () {
                  var example = JSON.parse(request.responseText);
  
                  var item = element.getAttribute("item");
                  currentIndex = item;
  
                  document.getElementById("data1").textContent = example[item].name;
                  document.getElementById("data2").src = example[item].age;
              }
              request.send();
          }
          .
          .
          .
  </code></pre>
  
  <p>I want to get these data in my (2) HTML page (for example):</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
      &lt;script src="example.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h4 id="data1"&gt;&lt;/h4&gt;
      &lt;h4 id="data2"&gt;&lt;/h4&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I saw this <a href="https://stackoverflow.com/questions/53774775/get-data-from-one-html-file-and-display-it-using-another-html-file">Get data from one html file and display it using another html file</a>, but I'm not sure how to use this for my case here.</p>
  
  <p>Sorry, I am new to this, so giving a detailed explanation for your solution would be very helpful. I am using vanilla JS only so please no jQuery. Any help would be appreciated</p>