Kobrar Kobrar - 1 year ago 69
HTML Question

Firefox <a download> issue

<a download>
, as I understand it, should download the response file on click.
I have the following code that doesn't work:

<a href="{{ download_url }}" style="cursor: pointer" download>Download PDF</a>

the relevant response header:

Content-Disposition: filename="Podsumowanie_wizyty_X_Y_2016-07-06.pdf"
Content-Type: application/pdf
Date: Thu, 15 Sep 2016 13:26:19 GMT
Server: WSGIServer/0.1 Python/2.7.11
Vary: Authorization, Cookie
x-frame-options: SAMEORIGIN

The returned file is viewed, not downloaded.

I have also discovered, that the following example works well:

But the following example views the file instead of downloading: example2

Everything seems to work as intended in chrome.

Can something be done about it on my end? It should be able to work without
Content-Disposition: attachment;
. I would like to avoid tinkering with headers if possible.

Answer Source

It's a known and documented behavior.

In your case your HTTP header is not well-formed, Content-Disposition needs one between inline and attachment (actually it's slightly more complex, see RFC1806 and RFC2616). inline is treated as default in FireFox (see MDN.) but another browser may behave differently (regardless priority of download over Content-Disposition, see later.)

From this moment also browsers behavior diverges (and this explain the differences between the two other examples): Chrome gives the priority to download attribute while FireFox gives the priority to Content-Disposition (see MDN.)

Unfortunately you do not have any option but fix your HTTP header (if you want to support FireFox.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download