That code won't work because you have added an s
to the end of window
.
You should be using a regular <a href="">
for this though.
To trigger a download instead of causing the image to be rendered in the browser window, you need to use the Content-Disposition
HTTP header to mark it as an attachment.
e.g. with Apache configuration:
<IfModule mod_headers.c>
<FilesMatch "\.jpeg$">
Header set Content-Disposition "attachment"
</FilesMatch>
</IfModule>
There is no sensible way to use JavaScript for this (although, I imagine you could use XMLHttpRequest to download the image, generate a data:
scheme URI from that, and then set location.href
to that URI while lying about the content type).