未捕获(承诺)类型错误:window.showSaveFilePicker 不是函数

问题描述 投票:0回答:1

我试图在点击下载按钮时打开保存对话框。它适用于 Chrome 和 Edge。但我的首要任务是 FireFox。它在 FireFox 中不起作用。

我正在使用 文件系统访问 API 打开保存对话框

当我在 FireFox 中运行时得到 Uncaught (in promise) TypeError: window.showSaveFilePicker is not a function error.

请帮我解决 FireFox 浏览器中的这个问题

提前致谢

document.querySelector(".btnTemp").onclick = async () => {
    const options = {
        types: [
            {
                description: "Test files",
                accept: {
                    "text/plain": [".txt"],
                },
            },
        ],
    };

    const handle = await window.showSaveFilePicker(options);

    const writable = await handle.createWritable();

    await writable.write("Hello World");
    await writable.close();

    return handle;
};
javascript file-system-access-api
1个回答
0
投票

请看这里:https://developer.mozilla.org/en-US/docs/Web/API/Window/showSaveFilePicker

showSaveFilePicker
是实验性的,目前仅支持 chrome、opera 和 edge。

© www.soinside.com 2019 - 2024. All rights reserved.