Javascript从服务器下载zip文件
我在web应用服务器上的预定义位置有一个zip文件。 我正在尝试使用Javascript下载该文件,我可以在FF中实现以下功能,但在Chrome中无法实现。 有没有人遇到过一种更好的方法,即跨浏览器友好方式(FF/Chrome/IE)?如果我能更好地强制执行“另存为”提示。如果有帮助的话,我会使用dojo工具包Javascript从服务器下载zip文件,javascript,dojo,Javascript,Dojo,我在web应用服务器上的预定义位置有一个zip文件。 我正在尝试使用Javascript下载该文件,我可以在FF中实现以下功能,但在Chrome中无法实现。 有没有人遇到过一种更好的方法,即跨浏览器友好方式(FF/Chrome/IE)?如果我能更好地强制执行“另存为”提示。如果有帮助的话,我会使用dojo工具包 function downloadZip() { var a = document.createElement("a"); document.body.appendC
function downloadZip() {
var a = document.createElement("a");
document.body.appendChild(a);
a.href = "/path_to_file/my.zip";
a.click();
}
试试这个
function downloadURI(uri, name)
{
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
}
试试这个
function downloadURI(uri, name)
{
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
}
我已经为此使用了
dojo/request/iframe
。这是我的密码:
iframe._currentDfd = null; // Force Dfd to be empty in case prior calls have not been cleared
iframe.post('path_to_file/file.zip',{
data: params,
handleAs: "html"
}).then(function (data) {
console.log('Then called' + data);
}, function (err) {
console.log(err);
});
这适用于Chrome、Firefox和IE。我使用了
dojo/request/iframe
。这是我的密码:
iframe._currentDfd = null; // Force Dfd to be empty in case prior calls have not been cleared
iframe.post('path_to_file/file.zip',{
data: params,
handleAs: "html"
}).then(function (data) {
console.log('Then called' + data);
}, function (err) {
console.log(err);
});
这适用于Chrome、Firefox和IE。为什么不干脆
window.location.href='/path\u to_file/my.zip'
?我也这么想,但我现在没有任何办法获取web应用程序的上下文。。。(据我所知)为什么不干脆window.location.href='/path\u to_file/my.zip'
?所以我想到了这一点,但此时我没有任何方法获取web应用程序的上下文。。。(据我所知)