-2

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 computer, 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 !

Thanasis
  • 91
  • 1
  • 7
  • This is something that you should ideally do at the server. Which server software are you using? – JJJ Apr 18 '15 at 16:57
  • Possible dupe of http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery – nestedloop Apr 18 '15 at 16:58
  • possible duplicate.. see this answer: http://stackoverflow.com/questions/10615797/utility-of-http-header-content-type-application-force-download-for-mobile – micahblu Apr 18 '15 at 16:59
  • possible duplicate of [Force a browser to save file as after clicking link](http://stackoverflow.com/questions/11353425/force-a-browser-to-save-file-as-after-clicking-link) – redbmk Apr 18 '15 at 17:02
  • possible duplicate of [How to force a Download File prompt instead of displaying it in-browser with HTML?](http://stackoverflow.com/questions/23825871/how-to-force-a-download-file-prompt-instead-of-displaying-it-in-browser-with-htm) – Bram Vanroy Apr 18 '15 at 17:02
  • Also possible duplicate of [Is it possible to initiate a download prompt in browser for recognized mime-types using only JavaScript (server-side approach)?](http://stackoverflow.com/questions/7763505/is-it-possible-to-initiate-a-download-prompt-in-browser-for-recognized-mime-type) and [Force to open “Save As…” popup open at text link click for pdf in HTML](http://stackoverflow.com/questions/3802510/force-to-open-save-as-popup-open-at-text-link-click-for-pdf-in-html) – redbmk Apr 18 '15 at 17:05
  • Hi people. Thanks. It is an apache php mysql combination. – Thanasis Apr 18 '15 at 18:33
  • this gives the answer in PHP .... http://stackoverflow.com/questions/364946/how-to-make-pdf-file-downloadable-in-html-link – Thanasis Apr 18 '15 at 18:59

1 Answers1

5

You 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.com/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.com/#feat=download to see if you want to do client or server side handling.

JBzd
  • 705
  • 3
  • 12
  • This method is relatively new and old browsers wouldn't support it ! – Thanasis Apr 20 '15 at 13:32
  • Thus why I linked caniuse.com, depending on the intended target it could work. We use that method at work for an web application that we only support chrome and use node-webkit to push a webkit wrapper presenting itself as our application for clients who will not install chrome. – JBzd Apr 20 '15 at 15:33
  • And why I put the server solution first. – JBzd Apr 20 '15 at 15:37