How to make a file available for inline dowload in html?

7

I wanted to create a link to a dowload in my HTML, but I did not want to save this content in a separate file, but in the html itself.

In images you can do something like this

<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />

Is it possible for links?

    
asked by anonymous 05.02.2014 / 13:02

3 answers

9

You can use MIME-type data:text/html

Render HTML code when you click on the link:

<a href="data:text/html;charset=utf-8,<html><body><h1>pt.stackoverflow</h1></body></html>">Clique aqui</a>

JSFiddle Example


HTML5

In HTML5 the tag <a> has gained a download feature .

Download HTML code when you click on the link:

<a href="data:text/html;charset=utf-8,<html><body><h1>pt.stackoverflow</h1></body></html>" download> Clique aqui </a>

Example in JSFiddle

Would that be what you want?

More information about DATA URI here . About the download feature in the <a> vi tag here .

    
05.02.2014 / 13:07
2

Just do this:

<img alt="Embedded Image" download="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />
    
05.02.2014 / 13:07
2

You can use an HTML5 attribute: download="pagina.html"

Example:

<a download="pagina.html" href="data:text/html;charset=utf-8,<html><body><h1>conteúdo/h1></body></html>">Clique aqui</a>
  • link
  • link
  • 05.02.2014 / 13:17