Using the Browser Prompt to Download a File

How to force a Download File prompt instead of displaying it in-browser with HTML?

This is something that you cannot absolutely control with HTML itself.

If the user is having a browser with PDF reading capabilities (or a plugin) and the corresponding settings to open PDF files in-browser, the PDF will open like that.

The PDF opens in a new tab simple because of your target="_blank", which has nothing to do with a download prompt.

If you are using HTML5 you can use the download attribute:

<a href="sample.pdf" download="sample.pdf">Download</a>

If you have a back-end service which you can control or you feel like fiddling with your Web Server, you can always look for setting the right Content-Disposition. See this SO question for some nice discussion on Content-Disposition.

How to prompt save as option for user to download file using chrome?

What you are asking isn't possible.

It's a user preference

Sample Image

ref: http://www.howtogeek.com/231002/how-to-change-the-chrome-download-folder-location/

The only thing you can do is letting the user rename server.log inside a input element or a window.prompt before saving

saveAs(blob, prompt('Filename?', 'server.log') || 'server.log');

Is it possible to initiate a download prompt in the browser for recognized MIME types using only JavaScript (client-side approach)?

There is a new download attribute in HTML5 that you can annote links with. It indicates to the browser that the resource should be downloaded rather than navigated to. Right now, it only works in Chrome, but it is part of the HTML spec and will hopefully be adopted by other browser soon.

Demo: http://html5-demos.appspot.com/static/a.download.html
More info: http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download



Related Topics



Leave a reply



Submit