提示用户使用“另存为”对话框保存文件? [英] Prompting user to save file using a 'Save-as' dialog?

查看:107
本文介绍了提示用户使用“另存为”对话框保存文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有这样的代码:

I currently have this code:

function download(filename, text) {
        var pom = document.createElement('a');
        pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        pom.setAttribute('download', filename);
        pom.click();
}

download('test.html', string);

字符串包含很多html代码,它们被写入到a.html文件中。
上述代码完美运行。点击一个按钮后,浏览器(chrome)会自动下载一个带有写入字符串内容的html文件。现在,我想要做的是,不要自动下载文件,而应该打开另存为对话框,并询问用户文件的位置和名称,然后将其下载到该位置。快速简单的答复将非常感激。

string contains a lot of html code that gets written in a.html file. The above code is working perfectly. On a button click, browser (chrome) automatically downloads an html file with the string content written in it. Now, what i want to do is, instead of chrome downloading the file automatically, it should open a save-as dialog box and ask user the location and name of the file and then download it to that location. A quick simple reply would be really appreciated.

推荐答案

我的浏览器被设置为自动下载所有文件的默认位置,只有这个文件但我的浏览器中的所有其他文件都是直接下载的,没有保存提示对话框。
。将浏览器中的设置更改为始终询问下载位置。

My browser was set to automatically download all files in default location which is why not only this file but all other files from my browser were downloaded directly without the save prompt dialogue. Changing the settings in browser to 'always ask the download location' worked.

这篇关于提示用户使用“另存为”对话框保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆