Pack a text file into an HTML file for download

1.3k Views Asked by At

Instead of creating an additional text file and provide a link to it, can one embed some texts into an HTML file and provide a link to download it? The solution should work for a static website.

2

There are 2 best solutions below

0
On

You should be able to base64 encode the file in the link, but you may want to do some cross-browser testing.

See Create a file in memory for user to download, not through server

1
On

If I understand correctly, you have a static website and you want to be able to create a link to a HTML page that should be downloaded instead of "viewed" in the browser.

The only way I can think of to solve this is to use the HTML 5 download attribute, like this:

<a href="somepage.html" download="somepage.html">Download</a>