本文介绍了如何提示另存为选项供用户使用chrome下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一种方法可以下载文件,只要该方法按预期运行,我只是看到IE用户在浏览器中的差异可以选择另存为文件,但是在chrome中,它可以直接下载文件,我们如何拥有该功能在chrome中,因此用户可以在保存文件时使用另存为选项,以便为文件命名?
I have method that is downloading file whenever this method called it is working as expected, I just see difference in browser in IE user has option to save As file but in chrome it directly download the file , How can we have that feature in chrome so user can use Save as option while saving the file so they can name the file ?
ctrl.js
function deleteFile(filename){
DitFactory.getFile(filename).then(function(response,$window){
console.log('data for download', response);
var data = JSON.stringify(response.data);
var blob = new Blob([data], { type: 'text/plain;charset=utf-8' });
FileSaver.saveAs(blob, 'server.log');
socket.emit('stopRecording',$scope.filename);
});
}
推荐答案
您要问的是'不可能的。
这是用户偏好设置
What you are asking isn't possible.
It's a user preference
ref:
唯一可以做的就是让用户在保存
The only thing you can do is letting the user rename server.log
inside a input element or a window.prompt
before saving
saveAs(blob, prompt('Filename?', 'server.log') || 'server.log');
这篇关于如何提示另存为选项供用户使用chrome下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!