I need to download a file (test.xml) and allow/prompt user to save the file on click on download button. The file resides in url "http://localhost/test/test.xml" .
I have added html code
<input type=button value="Download" onclick='javascript:download()/>
and javascript code is
function download() {
var url = "http://localhost/test/test.xml";
window.open(url, 'Download');
}
But this opens the page in new window. How do I prompt to download and save the file. Any inputs will be of help. Thanks
You have to change the content type in the header. You need to do some server scripting or configurate your webserver.
I Googled a link that will help you in the right direction: http://www.boutell.com/newfaq/creating/forcedownload.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With