HTML5: Force href to external file to download

This forum is for all Flare issues not related to any of the other categories.

HTML5: Force href to external file to download

Postby richt on Thu Sep 12, 2019 3:25 am

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?
richt
Propeller Head
 
Posts: 27
Joined: Wed Nov 28, 2018 6:38 am

Re: HTML5: Force href to external file to download

Postby Beaver on Thu Sep 12, 2019 5:03 am

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

Re: HTML5: Force href to external file to download

Postby Dave Lee on Thu Sep 12, 2019 5:49 am

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=""
Dave Lee
Master Propellus Maximus
 
Posts: 5641
Joined: Mon Mar 05, 2007 8:33 am
Location: UK


Return to Flare's General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron