href image link download on click

后端 未结 10 1945
失恋的感觉
失恋的感觉 2020-11-22 07:56

I generate normal links like: in a web app.

When I click on the link, it

10条回答
  •  自闭症患者
    2020-11-22 08:32

    You can't do it with pure html/javascript. This is because you have a seperate connection to the webserver to retrieve a separate file (the image) and a normal webserver will serve the file with content headers set so that the browser reading the content type will decide that the type can be handled internally.

    The way to force the browser not to handle the file internally is to change the headers (content-disposition prefereably, or content-type) so the browser will not try to handle the file internally. You can either do this by writing a script on the webserver that dynamically sets the headers (i.e. download.php) or by configuring the webserver to return different headers for the file you want to download. You can do this on a per-directory basis on the webserver, which would allow you to get away without writing any php or javascript - simply have all your download images in that one location.

提交回复
热议问题