HTML5下载属性

I tend to get caught up on the JavaScript side of the HTML5 revolution, and can you blame me?  HTML5 gives us awesome "big" stuff like WebSockets, Web Workers, History, Storage and little helpers like the Element classList collection.  There are, however, smaller features in HTML5 that we can appreciate; one of those would be the new download attribute.  The download attribute allows you to set a separate file download name than the actual link endpoint itself.

我倾向于追随HTML5革命JavaScript方面,您能怪我吗? HTML5为我们提供了诸如WebSockets ,Web Workers,History,Storage之类的很棒的“大”东西,以及Element classList集合之类的小帮手。 但是,HTML5中有一些较小的功能值得我们欣赏; 其中之一将是新的download属性。 download属性使您可以设置一个与实际链接端点本身不同的文件下载名称。

HTML (The HTML)

Place the download attribute on a link...

download属性放在链接上...


<!-- will download as "expenses.pdf" -->
<a href="/files/adlafjlxjewfasd89asd8f.pdf" download="expenses.pdf">Download Your Expense Report</a>


...and when the user clicks the link, the download attribute appears in the save dialog instead of the garbled mess that was there before. In this case, the file will be downloaded as expenses.pdf. The download attribute also triggers a force download, something that I used to do on the server side with PHP.

...并且当用户单击链接时,“ download属性将显示在“保存”对话框中,而不是以前出现的乱码。 在这种情况下,文件将被下载为expenses.pdfdownload属性还触发强制下载 ,这是我过去在PHP的服务器端执行的操作。

This attribute is extremely useful in cases where generated files are in use -- the file name on the server side needs to be incredibly unique, but the download attribute allows the file name to be meaningful to user.  The download attribute is one of those enhancements that isn't incredibly sexy but is a practical and easy to add.

在使用生成的文件的情况下,此属性非常有用-服务器端的文件名必须非常独特,但是download属性允许文件名对用户有意义。 download属性是这些增强功能中的一种,它并不是很性感,但实用且易于添加。

翻译自: https://davidwalsh.name/download-attribute

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值