Streaming live at 10am (PST)

Any workaround / How to add "download" attribute to file links with a specific class?

The download attribute allows files force to be downloaded on click like this:
<a href="../example.pdf" download>DOWNLOAD</a>

But one Webflow, the download attribute is forbidden, and I have to add custom code to create such download buttons.

Does anyone have a good workaround for this?

I have a rough idea of using javascript to insert download attribute to any link with a specific class or ID, e.g. <a href="file" class="makedownload">. I am not sure how exactly the script should look like.

Thanks a lot!

Hi @anthonychan2509, try this bit of custom code. Cheers, Pat

1 Like

The attribute download only works for same-origin URLs, or the blob: and data: schemes… So with Webflow using a CDN that rules this out.

See <a>: The Anchor element - HTML: HyperText Markup Language | MDN

1 Like

:+1: @webdev !

Thanks as well @PatSimons though tested not work on Webflow for the non-same-origin reason.