Use this method when viewing images or textual data. It allows you to open it in a seperate window. This will cause a popup blocker to react.
window.open(url,'_blank');
Use this method when the Content-Disposition
header is set to attachement
.
This will not change the url of the current window but will start the native browser
download dialog.
window.location = url;
This method is a middle ground between the two above, but it will only start a download. If you have the need for the browser to render an image in a new window then one of the methods above.
window.open(url,'_self');
My prefered way of doing this is to find a way to determine the Content-Type
and based on that
use the first or second under certain circumstances.
- if Content-Type: image / text
- use method 1
- if Content-Disposition: attachement or Content-Type: zip / gz / other / etc...
- use method 2