view raw
fwind fwind - 8 months ago 103
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
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.