Download A File At Different Location Using HTML5
It's not possible because this poses a security risk. People use fairly real information for their folder structure and accessing the folder names in itself poses an immediate risk. As described here:
Get browser download path with javascript
Most OSs tend to just default to a Download location and this is something the user decides through the Browser they use. Not the website.
In Chrome, Download location setting can be found at chrome://settings/downloads
How do I allow files to be downloaded to a folder other than the Downloads folder?
Its not possible as the download location is controller by the browser.
If you want to know more give the page a read Download A File At Different Location Using HTML5
Using HTML5/JavaScript to generate and save a file
OK, creating a data:URI definitely does the trick for me, thanks to Matthew and Dennkster pointing that option out! Here is basically how I do it:
1) get all the content into a string called "content" (e.g. by creating it there initially or by reading innerHTML of the tag of an already built page).
2) Build the data URI:
uriContent = "data:application/octet-stream," + encodeURIComponent(content);
There will be length limitations depending on browser type etc., but e.g. Firefox 3.6.12 works until at least 256k. Encoding in Base64 instead using encodeURIComponent might make things more efficient, but for me that was ok.
3) open a new window and "redirect" it to this URI prompts for a download location of my JavaScript generated page:
newWindow = window.open(uriContent, 'neuesDokument');
That's it.
How to specify download location in Html using JavaScript
Whether the browser asks the user or not is down to the preferences in the browser.
You can't bypass those preference, otherwise it would violate user's security.
What you can do is make sure you're sending the browser as much information as possible to help it make for a good user experience. If you're not already doing so, be sure to include a Content-Disposition header in the response to the download request, including a filename field:
Content-Disposition: attachment; filename=test.csv
Also see these other stackoverflow questions:
Specify default download folder - possibly with JavaScript?
Set file download destination using ExtJs
How to trigger a file download when clicking an HTML button or JavaScript
For the button you can do
<form method="get" action="file.doc">
<button type="submit">Download!</button>
</form>
Related Topics
How to Pass Variables and Data from PHP to JavaScript
How to Save an Html5 Canvas as an Image on a Server
Adjust Width and Height of Iframe to Fit With Content in It
Load More Posts Ajax Button in Wordpress
What Are Cookies and Sessions, and How Do They Relate to Each Other
Angularjs Post Fails: Response For Preflight Has Invalid Http Status Code 404
How to Show Progress Bar While Loading, Using Ajax
Encryption in JavaScript and Decryption With PHP
Send Formdata and String Data Together Through Jquery Ajax
How to Use a C++ Library from Node.Js
How to Modify the Url Without Reloading the Page
JavaScript Function Doesn't Work When Link Is Clicked
After Submitting a Post Form Open a New Window Showing the Result
How to Detect Div'S Dimension Changed
Html/JavaScript: How to Access Json Data Loaded in a Script Tag With Src Set
How to Add/Update an Attribute to an HTML Element Using JavaScript