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.pdf
。 download
属性还触发强制下载 ,这是我过去在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
属性是这些增强功能中的一种,它并不是很性感,但实用且易于添加。