When I click on save as HTML button its Download all content of web page but i have require to Download some for specific content from all content.
function download(filename, contents) {
const anchor = document.createElement('a');
anchor.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(contents));
anchor.setAttribute('download', filename);
anchor.style.display = 'none';
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
}
const btn = document.querySelector('#save-btn');
btn.addEventListener('click', (evt) => {
const container = document.createElement('div');
const html = document.createElement('html');
html.innerHTML = document.documentElement.innerHTML;
container.appendChild(html);
download('index.html', container.innerHTML);
});
<p>Hello World</p>
<button id="save-btn">Save as HTML</button>
<div>
<p>Hello World-1</p>
<p>Hello World-2</p>
<p>Hello World-3</p>
</div>
On above HTML Example, when i click on save as HTML Button i have download some of portion of file like download div content instead of all content. in sort when I open download file it display only this content:
<div>
<p>Hello World-1</p>
<p>Hello World-2</p>
<p>Hello World-3</p>
</div>