A-tag implementation in HTML Click to download

Source: Internet
Author: User

Usually when we write the project will encounter upload download what, after uploading the file will be stored in the file path to the database in order to download, if you want not to download directly in the background, you can take the file path to a tag attribute href;

<a href= "/user/test/xxxx.txt" > click to download </a>

This will download the file directly when the user opens the browser and clicks the link.

However, there is a situation, such as txt,png,jpg, and so on, these browsers support directly open files will not perform the download task, but will open the file directly, this time need to add an attribute "download" to the A tag;

<a href= "/user/test/xxxx.txt" download= "filename. txt" > click Download </a>

Here download can also not write any information, will automatically use the default file name.

Here is a description of some IE does not seem to support, only through the background code to engage.

A-tag implementation in HTML Click to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.