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
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
Writing JSON Object to .JSON File on Server
How to Cause a Redirect to Occur Before PHP Script Finishes
Userland Multipart/Form-Data Handler
How to Include Config.PHP Efficiently
How to Merge Array and Preserve Keys
How to Get the Length of Longest String in an Array
How to Send a Http/2 Post Request in PHP
What's the Best Way to Localise a Date on Laravel
Avoiding MySQL Injections with the Zend_Db Class
Alternative to File_Get_Contents
Can PHP Asynchronously Use Sockets
How to Clear PHP's Gettext Cache Without Restart Apache Nor Change Domain
Symfony 2 Load Different Template Depending on User Agent Properties
How to Set Curlopt_Cainfo Globally for PHP