title: How can I save an html file and remove script and unwanted tag when dowloading?
body: <p>I have an <a href="/questions/tagged/html" class="post-tag" title="show questions tagged &#39;html&#39;" rel="tag">html</a> file with lots of tags with <code>contenteditable=&quot;true&quot;</code> attribute. I also added a lot of jquery/js inside.</p>
  <p>What I'm trying to achieve is:</p>
  <ol>
  <li>Let user modify the content --&gt; ok with <code>contenteditable</code> attribute</li>
  <li>Let user download the modified file --&gt; ok with the snippet below</li>
  <li>When clicking on download button, remove all content between &quot;Delete&quot; and &quot;Delete End&quot; comments, and also remove all <code>&quot;contenteditable=&quot;true&quot;</code> attributes --&gt; not ok</li>
  </ol>
  <p>I also found this download snippet which is drastically shorter than the one I use in the following snippet, but don't know which is better, safer?</p>
  <pre><code>&lt;a onclick=&quot;this.href='data:text/html;charset=UTF-8,'+encodeURIComponent(document.documentElement.outerHTML)&quot; href=&quot;#&quot; download=&quot;index.html&quot;&gt;Download&lt;/a&gt;
  </code></pre>
  <p>Here is an example of my file:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width"&gt;
    &lt;!--Delete Start--&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"&gt;&lt;/script&gt;
    &lt;!--Delete End--&gt;
    &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body style="margin: 0; padding: 0 !important;background-color: #F2F2F2;"&gt;
    &lt;div contenteditable="true"&gt;
      &lt;p style="margin: 0 0 8px;"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;!--Delete Start--&gt;
    &lt;div&gt;
      &lt;input type="button" id="add" value="add content"&gt;
      &lt;input type="button" id="del" value="remove content"&gt;
    &lt;/div&gt;
    &lt;!--Delete End--&gt;
  
  
    &lt;!--Delete Start--&gt;
    &lt;div&gt;
      &lt;a href="#" id="donwload-link" onClick="myFunction()"&gt;download html content&lt;/a&gt;
    &lt;/div&gt;
    &lt;!--Delete End--&gt;
  
  
    &lt;!--Delete Start--&gt;
    &lt;script&gt;
      function myFunction() {
        var content = document.documentElement.innerHTML;
        download(content, "index", "html")
      }
  
      function download(content, fileName, fileType) {
        var link = document.getElementById("donwload-link");
        var file = new Blob([content], {
          type: "html"
        });
        var donwloadFile = fileName + "." + fileType;
        link.href = URL.createObjectURL(file);
        link.download = donwloadFile
      }
    &lt;/script&gt;
    &lt;!--Delete End--&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>