less than 1 minute read

This is a sample code to save the HTML document as a file programmtically which you can use “save” function to be used somewhere such as a special event.

const save = function () {
	var htmlContent = new Array(document.documentElement.innerHTML);
	var bl = new Blob(htmlContent, { type: 'text/html' });
	var a = document.createElement('a');
	a.href = URL.createObjectURL(bl);
	a.download = 'test-document';
	a.hidden = true;
	document.body.appendChild(a);
	a.click();
};

Categories: , ,

Updated:

Comments