Reputation: 38025
We want to allow a user to download a picture via a button from our website. We've got the basic download working ok (it saves it to the disk) but we do it by opening up a new window...
window.open('mypicture', '_blank');
Unfortunately this creates a new tab in Chrome which does not go away. We don't have the most sophisticated users and they might become confused if the screen suddenly goes blank.
We tried it with...
location.href='mypicture'
This works great in IE, but in Chrome it just ignores the download completely.
Is there any other way to force download the picture without opening a new window?
Upvotes: 3
Views: 8690
Reputation: 38025
Perhaps this is a bug in Chrome (FF too)? I just tried it with a link and it works fine.
<a href="mypicture">Download</a>
Upvotes: 0
Reputation: 411
Ideally, you should send http header in order to prompt the picture to be downloaded like
Content-Disposition: attachment; filename="downloaded.jpg"
..so you should point your link to a PHP script (or whatever), which sends a picture with proper headers.
Upvotes: 2