Force a browser to save file as after clicking link [duplicate]

Solution 1:

You could use the HTML5 download attribute like so:

<a href="path/to/file" download>Click here to download</a>

This opens a "save as" dialog regardless of file type without taking you away from the page.

Solution 2:

If you control the server, then you should set it up to send a Content-Disposition: attachment header for the files you wish to be downloaded (e.g. you can do this in an .htaccess file to make all .jpegs in a particular directory).