fwind fwind - 2 months ago 7
HTML Question

Create GWT Anchor element with download attribute

I want to create a link element with the html download attribute from my GWT Presenter. Using an UI-Binder is not an option. I tried using an Anchor object but could not find an option there. Is it possible without using JavaScript?

j.s j.s
Answer
Anchor a = new Anchor("download something", "download.html");
a.getElement().setAttribute("download", "downloadname.html");

Note: Unfortunately gwt does not allow attributes without a value. So you cannot create a link of the form: <a href"..." download>...</a>. But according to the specs of the download attribute, it is valid to set a value. The value of the attribute (downloadname.html) will then be used as the pre-filled file name in the Save prompt.

Comments