Created
May 11, 2023 11:04
-
-
Save BekNaji/b536271e1563c96bd447b002a5ce307d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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