I've a very simple html+javascript page using the document.getElementByID().innerHTML to write a specific div. I'd like to add a button or a link to save this div directly as CSV on the client side without having to write a file or into the DB on the server. How can I achieve this in javascript? <html> <head> <script type='text/javascript'> function MyFunction() { if certain condition is true document.getElementById('SectionDiv').innerHTML= someHTMLcode+document.getElementById('SectionDiv').innerHTML; else do nothing } </script> <style type='text/css'> SomeCSS </style> <!--[if IE]> <style> SomeSpecificIE_CSS </style> <![endif]--> </head> <body> <div id='main'> <button type='button' onclick='MyFunction()'>ButtonText</button> </div> <div id='SectionDiv'> MyFunction is writing into this Div </div> </body> </html> Code (markup):
Because Javascript doesn't have a method for generating an actual file or an HTTP header that would prompt the browser to download javascript content in place of a file. You have to go to the server. Coding everything up until that point is simple. If it was possible, I would have written an .htaccess file generator for Windows users that didn't need to go to the server to generate the file by now.