0

I want to create an HTML page content with JS, e.g.:

var html = '<html>';
    html += '<head><title>Page title</title></head>';
    html += '<body>...</body>';
    html += '</html>';

then enable a user to download this as an HTML page somehow. I am quite sure JS will not let me prompt to download it, but maybe there is a way to open it in a separate tab as an HTML page so they could right click and save it?

sdvnksv
  • 9,350
  • 18
  • 56
  • 108
  • Where is the rest of the relevant source code? What are you doing with the `html` variable? – NewToJS Oct 01 '17 at 19:20
  • @NewToJS, html is the var that contains all the code I want to save as an HTML page. I can do it on button click or any other way. Now I wonder how to do the saving itself. – sdvnksv Oct 01 '17 at 19:22
  • But where/how are you trying to use/render it on the page? This the moment that variable contains the html but isn't being used. – NewToJS Oct 01 '17 at 19:24
  • Check out: https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser and https://stackoverflow.com/a/4551467/544779 (there are more, pls. search before posting - Google first, SO second) – Mörre Oct 01 '17 at 19:26
  • @NewToJS, I am not not rendering the contents of the html var, it's just in the JS scope. I can prompt to save it on a button click or page load - but that another question. – sdvnksv Oct 01 '17 at 19:27

0 Answers0