Hi guys I am using a simple html link to save a generated .xml file
<a href="./serverfile.xml">Save your file</a>
Problem is that, when I click on the above link, instead of opening the file dialog box to save the file in my local windows puter, the browser opens it like a web page.
Is there any solution to the problem? Maybe some JavaScript or something.... Also is it possible to open the file dialog box at a defined folder path?
Thank you so much !
Hi guys I am using a simple html link to save a generated .xml file
<a href="./serverfile.xml">Save your file</a>
Problem is that, when I click on the above link, instead of opening the file dialog box to save the file in my local windows puter, the browser opens it like a web page.
Is there any solution to the problem? Maybe some JavaScript or something.... Also is it possible to open the file dialog box at a defined folder path?
Thank you so much !
Share Improve this question asked Apr 18, 2015 at 16:54 ThanasisThanasis 4495 silver badges10 bronze badges 8- This is something that you should ideally do at the server. Which server software are you using? – JJJ Commented Apr 18, 2015 at 16:57
- Possible dupe of stackoverflow./questions/3749231/… – nestedloop Commented Apr 18, 2015 at 16:58
- possible duplicate.. see this answer: stackoverflow./questions/10615797/… – micahblu Commented Apr 18, 2015 at 16:59
- possible duplicate of Force a browser to save file as after clicking link – redbmk Commented Apr 18, 2015 at 17:02
- possible duplicate of How to force a Download File prompt instead of displaying it in-browser with HTML? – Bram Vanroy Commented Apr 18, 2015 at 17:02
1 Answer
Reset to default 6You could do so with headers from the server side with the following headers:
Content-Disposition: attachment; filename=Filename.xml
If you specify the server side language, if you have control on that side, I can change that to code instead of generic header.
Or from the client side via a html5 attribute: http://www.sitepoint./new-html5-attributes-hyperlinks-download-media-ping/.
<a href="./serverfile.xml" download="Filename.xml">Save your file</a>
That may not work in all browsers, see http://caniuse./#feat=download to see if you want to do client or server side handling.