添加“;密码”;键入Google Apps Script inputBox

Adding "password" type to Google Apps Script inputBox

本文关键字:Apps Script Google inputBox 密码 添加 键入      更新时间:2023-09-26

是否可以将"密码"类型分配给Google Apps脚本输入框,这样文本就不会显示?

以下操作很好,但输入字段是一个简单的文本框,显示的是文本而不是"••••":

Browser.inputBox('Please enter your password');

我有一个带有关联脚本的谷歌工作表,该脚本自动填充一些单元格,其中包含从外部API检索到的信息。API需要简单的身份验证,这就是我提示用户输入用户名和密码的原因(这是针对内部工具的,因此询问密码没有问题,密码没有被存储或其他任何问题)。

根据Sandy Good的评论,我最终使用了一个带有HTML服务的自定义对话框。

以下操作非常适合显示输入类型"password"并将值传递给我的谷歌脚本:

pw_input.html

<script>
  function updateInfo(form) {
    google.script.run.myOtherScript(form.password.value);
    google.script.host.close();
  }
</script>
<form>
  Password:
  <input type="password" name="password">
  <input type="button" value="OK" onclick="updateInfo(this.form)" />
</form>

main.gs

function myMainFunc() {
  onOpen();
  var html = HtmlService.createHtmlOutputFromFile('pw_input')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi()
      .showModalDialog(html, 'Please enter your password');
};

其他脚本.gs

function myOtherScript(promptResponse) {
  etc...
};