Page 1 of 1

HTML5: Force href to external file to download

Posted: Thu Sep 12, 2019 3:25 am
by richt
Hi all,

A few of my HTML5 pages have hyperlinks to files (plain text, but with a custom file type). If the user clicks these links in their browser, I need to force these links to download rather than opening directly in the browser.

HTML5 supports the "download" attribute, as in the following example:

Code: Select all

<a href="path/to/file" download>Click here to download</a>
But when I try to include this in my topic files, the Text editor gives me the warning:

Code: Select all

'>' is an unexpected token. The expected token is '='.
I can't seem to find a way around it. The clumsy way is to tell the user to right-click the link, but I need to make this idiot-proof.

So, has anyone else successfully implemented the download attribute?

Re: HTML5: Force href to external file to download

Posted: Thu Sep 12, 2019 5:03 am
by Beaver
I got also same error
This works:

Code: Select all

<a href="path/to/file">Click here to download</a
Note: for some file types used .zip format

Re: HTML5: Force href to external file to download

Posted: Thu Sep 12, 2019 5:49 am
by NorthEast
richt wrote:HTML5 supports the "download" attribute, as in the following example:

Code: Select all

<a href="path/to/file" download>Click here to download</a>
It doesn't work because Flare uses XHTML, not HTML.

In XHTML, you can't use shorthand (minimisation) for attributes; all attributes must have a value.
https://www.w3schools.com/html/html_xhtml.asp

So instead of using download , you need to use download=""