// Download the current HTML as a file document.getEle"> // Download the current HTML as a file document.getEle">

How to Download the current HTML as a file using JavaScript

      <div class=”text-right mt-4″>

        <button id=”downloadBtn” class=”btn btn-outline-secondary”>Download HTML</button>

      </div>

  
<script>
    // Download the current HTML as a file
    document.getElementById('downloadBtn').addEventListener('click', function () {
      const html = document.documentElement.outerHTML;
      const blob = new Blob([html], { type: 'text/html' });
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = 'born_on_1st_profile.html';
      document.body.appendChild(a);
      a.click();
      a.remove();
      URL.revokeObjectURL(url);
    });
  </script>



Leave a Reply