admin管理员组文章数量:1321060
I've been looking about for a while now and I cant find a proper answer.
Basically I have a web page that lets the user enter somevalues and download a specific file depending on the values entered. All is working but, I want to enable the user to select where to save the file to, instead of just the browser saving to the default download location.
I am using the follownig to initiate the download.
/**
* Get URL for data file and ensure user wants to download it
**/
function getResultDataHandler(result, messages) {
var dataURL = result.value.url;
var r = confirm("Save File?");
if (r == true) {
download(dataURL);
}
else {
console.log("Canceled");
}
showMessage("", true);
}
/**
* Open the download dialog
**/
function download(dataURL) {
console.log("downloading");
window.open(dataURL, 'Download');
}
I've been looking about for a while now and I cant find a proper answer.
Basically I have a web page that lets the user enter somevalues and download a specific file depending on the values entered. All is working but, I want to enable the user to select where to save the file to, instead of just the browser saving to the default download location.
I am using the follownig to initiate the download.
/**
* Get URL for data file and ensure user wants to download it
**/
function getResultDataHandler(result, messages) {
var dataURL = result.value.url;
var r = confirm("Save File?");
if (r == true) {
download(dataURL);
}
else {
console.log("Canceled");
}
showMessage("", true);
}
/**
* Open the download dialog
**/
function download(dataURL) {
console.log("downloading");
window.open(dataURL, 'Download');
}
Share
Improve this question
edited Jul 13, 2011 at 10:28
Anto K
asked Jul 13, 2011 at 10:11
Anto KAnto K
431 silver badge4 bronze badges
1 Answer
Reset to default 8Whether the browser asks the user or not is down to the user's preferences in the browser. You can't bypass those preferences (nor, really, should you — if the user wants to always download files to a specified location, they should be allowed to do that).
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 (you probably are), be sure to include a Content-Disposition
header in the response to the download request, including a filename
field:
Content-Disposition: attachment; filename=foo.csv
But I'm guessing you're already doing that part.
本文标签: javascriptUser specified download locationStack Overflow
版权声明:本文标题:javascript - User specified download location - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742093059a2420381.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论