01 May 2026

How to download/create content in doc from website by adding code in chrome console?

 Download/Create content in doc from website by adding code in chrome console




function exportHTMLtoDoc(elementId, fileName = 'document') {

    // 1. Get the specific div content

    const 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'></head><body>";

    const footer = "</body></html>";

    

    const sourceHTML = header + document.getElementById(elementId).innerHTML + footer;

    

    // 2. Create a Blob with MS Word MIME type

    const source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);

    

    // 3. Create a temporary download link

    const fileDownload = document.createElement("a");

    document.body.appendChild(fileDownload);

    fileDownload.href = source;

    fileDownload.download = fileName + '.doc';

    fileDownload.click();

    document.body.removeChild(fileDownload);

}



(function(){

  const el = document.querySelector('[data-testid="view-lesson-content"]');

  if(!el){console.log("Element not found"); return;}

  el.id='temp-export';

  exportHTMLtoDoc('temp-export','My_Web_Export');

})();

No comments:

Post a Comment

How to download/create content in doc from website by adding code in chrome console?

 Download/Create content in doc from website by adding code in chrome console function exportHTMLtoDoc(elementId, fileName = 'document...