为什么我的 Google 表单插件会打开一个新标签页?

Why does my Google Forms add-on open a new tab?

我正在使用 Google Apps 脚本制作一个 Google 表单插件,其 UI 有一个 HTML 文件。 我几乎完成了快速入门并更改了一些内容。

尴尬的是我第一次做任何类型的 HTML。

在我的 UI 中,我有一个按钮:

<div class="sidebar branding-below">
      <form>
        <div class="block" id="button-bar">
          <button id="deactivate" class="action" onclick="deactivatePressed()">Deactivate</button><br><br>
          <div id="deactivation-confirmation"></div>
        </div>
      </form>
    </div>

这是调用 google 实际执行工作的应用程序脚本的相应 javascript:

function deactivatePressed() {
    google.script.run.addTrigger(false);
    document.getElementById('deactivation-confirmation').innerHTML = "Success!";
}

按钮出现,函数调用成功。

问题是按下此按钮还会打开一个新的空白选项卡,指向特定的 link,如下所示:

https://n-it2esyxcfj91uyg675645seyxh42jvgbfydr5e6u56y-0lu-script.googleusercontent.com/userCodeAppPanel?

在控制台中,它 运行 显示一条错误消息:

Unsafe JavaScript attempt to initiate navigation for frame with origin 'https://docs.google.com' from frame with URL 'https://n-it2esyxcfj91uyg675645seyxh42jvgbfydr5e6u56y-0lu-script.googleusercontent.com/userCodeAppPanel'. The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

如何确保脚本为 运行 时不会打开新选项卡?

我确定它在 HTML/js 而不是 Google Apps 脚本代码,因为我注释掉了 Google Apps 脚本函数的主体,问题仍然存在发生了。

这是因为按钮在 <form> 标签内。

改成这样:

<div class="sidebar branding-below">
   <div class="block" id="button-bar">
      <button id="deactivate" class="action" onclick="deactivatePressed()">Deactivate</button><br><br>
      <div id="deactivation-confirmation"></div>
   </div>
</div>