HTML5: Force href to external file to download

This forum is for all Flare issues not related to any of the other categories.
Post Reply
richt
Propeller Head
Posts: 42
Joined: Wed Nov 28, 2018 6:38 am

HTML5: Force href to external file to download

Post 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?
Beaver
Propeller Head
Posts: 45
Joined: Fri Mar 10, 2017 4:09 am

Re: HTML5: Force href to external file to download

Post 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
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: HTML5: Force href to external file to download

Post 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=""
Post Reply