How can I create an Image Download Link in HTML for a Mobile Page?

后端 未结 4 1516
南笙
南笙 2021-02-19 04:22

I have a mobile html page which contains images. I want to create a button or a link which is used for a download of an image. The image should then be saved to the users mobile

4条回答
  •  [愿得一人]
    2021-02-19 05:13

    Support for download attribute: http://caniuse.com/download

    You can set headers on the server, if that's an option for you. The HTTP header you want to send is Content-Disposition: attachment; filename="imagename.jpg".

    Differs depending on your server..

    In Node/Express:

    // only on imgs
    function(req, res){
        res.setHeader('Content-disposition', 'attachment; filename=imagename.jpg');
    }
    

    In the HTML:

    Download link
    

    Server will send Content-Disposition header when it gets the request for the file and force browsers to download.

提交回复
热议问题