The XML namespaces will be specified in the header section. This source HTML will be encoded and appended with the data URI that is linked with a download element created dynamically.
<div id="source-html"> <h1> <center>Artificial Intelligence</center> </h1> <h2>Overview</h2> <p> Artificial Intelligence(AI) is an emerging technology demonstrating machine intelligence. The sub studies like <u><i>Neural Networks</i>, <i>Robatics</i> or <i>Machine Learning</i></u> are the parts of AI. This technology is expected to be a prime part of the real world in all levels. </p> </div> <div class="content-footer"> <button id="btn-export" onclick="exportHTML();">Export to word doc</button> </div>
With these specifications, the source HTML will be encoded to form the URI. Then, a download link element will be created dynamically and the URI is hyperlinked with this element. Then, the click event is triggered programmatically to download the word document with the exported HTML data.
Thank You so much to share such a helpful code with us.
Thanks for a wonderful tutorial. The generated file does not open on any mobile device. Ive tried with different softwares. Any suggestions?
Can you give me details on issue you are facing, any error messages? screenshots etc.
Great! Thank you very much.
this script doesn’t allow the images
Dada, will write another article for that.
Thank you very mucho for a simple yet functional solution. I’ve tried with inline styles and the word document reflects those styles. However, if you add a style tag in the head, apparently the resulting word doc does not take the styles. I could find a way to parse the style tags into inline style attributes, but I thought it could be a great idea to have a style tag converted to a word stylesheet. Any suggestions??