【问题标题】:Create GWT Anchor element with download attribute创建具有下载属性的 GWT Anchor 元素
【发布时间】:2016-09-27 15:44:51
【问题描述】:

我想用我的 GWT Presenter 中的 html download attribute 创建一个链接元素。使用 UI-Binder 不是一种选择。我尝试使用 Anchor 对象,但在那里找不到选项。不使用 JavaScript 可以吗?

【问题讨论】:

    标签: java html gwt


    【解决方案1】:
    Anchor a = new Anchor("download something", "download.html");
    a.getElement().setAttribute("download", "");
    

    这将创建一个下载属性为空的链接。

    如果您为属性设置了一个值,该值将用作保存提示中的预填充文件名,例如:

    a.getElement().setAttribute("download", "downloadname.html")
    

    【讨论】:

    • 属性总是有一个值。 download 被浏览器解析时相当于download=""
    • 感谢@Thomas Broyer 提供的信息。我更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    相关资源
    最近更新 更多