Browser Download file

Source: Internet
Author: User

One of the simplest ways we might think of is to a link a picture directly to a button tag, like this:

<a href= "large.jpg" > Downloads </a>

However, although the idea is good, the actual effect is not what we want, because the browser can directly browse the picture, so we click the "Download" link below, and is not to download the image, but in a new window to browse the image directly.

For example, we want to click on the "Download" link to download the image instead of browsing, adding a download property directly to:

<a href= "large.jpg" download> download </a>


Results in Chrome (Firefox browser is invalid because of cross-domain restrictions):
Change to <a href= "Index_logo.gif" download= "_5332_.gif" > Download </a>

Whether to support monitoring of download properties
To monitor whether the current browser supports download attributes, a single line of JS code is available, as follows:

var issupportdownload = ' Download ' in Document.createelement (' a ');


Browser Download file

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.