Skip to content

Instantly share code, notes, and snippets.

@BekNaji
Created May 11, 2023 11:04
Show Gist options
  • Save BekNaji/b536271e1563c96bd447b002a5ce307d to your computer and use it in GitHub Desktop.
Save BekNaji/b536271e1563c96bd447b002a5ce307d to your computer and use it in GitHub Desktop.
function exportHTML(){
var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' "+
"xmlns:w='urn:schemas-microsoft-com:office:word' "+
"xmlns='http://www.w3.org/TR/REC-html40'>"+
"<head><meta charset='utf-8'><title>Export HTML to Word Document with JavaScript</title></head><body>";
var footer = "</body></html>";
var sourceHTML = header+document.getElementsByClassName("fr-view")[0].innerHTML+footer;
var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);
var fileDownload = document.createElement("a");
document.body.appendChild(fileDownload);
fileDownload.href = source;
fileDownload.download = 'document.doc';
fileDownload.click();
document.body.removeChild(fileDownload);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment