提示用户使用"另存为"对话框保存文件?

Abd*_*bar 7 html javascript save-as

我目前有这个代码:

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);
Run Code Online (Sandbox Code Playgroud)

string包含许多以.html文件编写的html代码.
上面的代码工作正常:点击一下按钮,浏览器(chrome)会自动下载一个带有写入其中的字符串内容的html文件.

现在,我想要做的是,而不是自动下载文件的chrome,它应该打开一个"另存为"对话框,并询问用户文件的位置和名称,然后将其下载到该位置.

一个快速简单的回复将非常感激.

Abd*_*bar 5

我的浏览器设置为自动在默认位置下载所有文件,这就是为什么不仅下载此文件,而且直接从浏览器下载所有其他文件而没有保存提示对话框的原因。将浏览器中的设置更改为“总是询问下载位置”是可行的。