You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改window.showSaveFilePicker()函数弹出窗口的标题

如何修改window.showSaveFilePicker()弹出窗口的标题

当前调用window.showSaveFilePicker()时,弹出的保存窗口使用浏览器默认标题,想要自定义这个标题。原代码及弹窗截图如下:

保存窗口默认样式

原代码:

async function getNewFileHandle() {
  const opts = {
    types: [
      {
        description: "Text file",
        accept: { "text/plain": [".txt"] },
      },
    ],
  };
  return await window.showSaveFilePicker(opts);
}
getNewFileHandle();

解决方案

目前标准的File System Access API并没有定义设置保存窗口标题的参数,但Chrome、Edge这类Chromium系浏览器支持一个非标准的title配置项,直接加到选项对象里就能自定义标题:

修改后的代码:

async function getNewFileHandle() {
  const opts = {
    title: "自定义保存文件", // 填入你需要的标题文本
    types: [
      {
        description: "Text file",
        accept: { "text/plain": [".txt"] },
      },
    ],
  };
  return await window.showSaveFilePicker(opts);
}
getNewFileHandle();

注意事项

  • 这个title是非标准特性,仅在Chromium内核浏览器生效,Firefox、Safari等浏览器会忽略该参数,继续显示默认标题。
  • 如果要兼容全浏览器,目前没有标准方法自定义这个弹窗标题,只能使用浏览器默认的标题样式。

内容的提问来源于stack exchange,提问作者shekhar kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 01:26:01