1

I'm generating a HTML / Javascript page using PHP.

I'd like to offer to my users, after the preview of the page, the chance to save / download, programmatically (not interactively using browser functionalities ....), the code of this HTML / Javascript page.

I've tried to search on the web for any examples but nothing appears.

Any suggestion / example? Thank you very much in advance!

Cesare

Cesare
  • 1,629
  • 9
  • 30
  • 72
  • I think PHP is kind of irrelevant here; the process would be the same regardless of where the page came from. – Don't Panic Aug 11 '16 at 18:41
  • 1
    Possible duplicate of [How to download the current page as a file / attachment using Javascript?](http://stackoverflow.com/questions/7271524/how-to-download-the-current-page-as-a-file-attachment-using-javascript) – Don't Panic Aug 11 '16 at 18:41
  • ok "not exactly" what I need but useful. The sample in that post download the "body" content of the HTML page not the "all" HTML / Javascript code page – Cesare Aug 11 '16 at 19:07
  • Oh, I thought it looked like the commented out part in the accepted answer would get the entire page. Does it not? – Don't Panic Aug 11 '16 at 19:18
  • 1
    Just tested and like the answer said using`document.documentElement.innerHTML` downloads the entire page (head and body) doesn't it for you? Try maybe with `outerHTML`. – yuriy636 Aug 11 '16 at 19:32
  • I've tried to use the commented row but something goes wrong when I use it with my page. Anyway using the commented line you download ALL the code, so also the javascript at the end of the page and this is .... too much. I've tried with the HTML code in the sample ... – Cesare Aug 11 '16 at 19:40

1 Answers1

0

I've solved using the solution shown in this post ...

https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/

I've put my code in a variable and then show it in the text area.

It's working !!

Cesare
  • 1,629
  • 9
  • 30
  • 72