英文:
What is the meaning of download property in ionic 4 ion-button?
问题
我想在使用ionic 4开发的Web应用中实现一个下载按钮。我看到可以在ion-button中添加一个download属性。
Download: 此属性指示浏览器下载URL而不是导航到它,因此用户将被提示将其保存为本地文件。如果属性具有值,则在保存提示中用作预填的文件名(用户仍然可以更改文件名)。
看起来这个属性将是保存提示中的文件名,所以我的问题是要把下载URL放在哪里。
英文:
I would like to implement a download button in a web app developed with ionic 4. I read that I can add a download property in ion-button
>> Download: This attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want).
It seems that the attribute will be the file name in the save prompt, so my question is where to put the download url.
答案1
得分: 4
<ion-button download="MyFavicon" href="/assets/icon/favicon.png">My Icon</ion-button>
根据我在Ionic文档中找到的信息并进行测试,download属性似乎与锚标签的download属性完全相同。我在ion-button文档[1]中找到了关于href属性的信息:
> 包含超链接指向的URL或URL片段。如果设置了此属性,将呈现为锚标签。
看起来带有href属性的ion-button呈现为锚标签,然后可以使用download属性进行下载。在测试期间,我只能下载我的应用程序域内的图像。我猜这是一个跨域问题。
希望这有所帮助。
[1]: https://ionicframework.com/docs/api/button
英文:
<ion-button download="MyFavicon" href="/assets/icon/favicon.png">My Icon</ion-button>
Based on what I could find in the Ionic docs and was able to test out, the download attribute seems to work exactly like the anchor tag download attribute. I found this in the ion-button docs regarding the href property:
> Contains a URL or a URL fragment that the hyperlink points to. If this property is set, an anchor tag will be rendered.
Seems like the ion-button with an href property renders as an anchor tag which can then use the download attribute. During testing I was only able to download images within my app's domain. I'm guessing its a cross-origin thing.
Hope this helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论