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

Google Apps Script侧边栏按钮触发加载Gmail草稿失效问题

Fix for Sidebar Clearing on Button Click in Google Apps Script Mail Merge

Ah, I see the root issue here! Your reload button is wrapped inside a <form> element, and by default, any button inside a form triggers the browser's default form submit behavior. When you click "reload", this causes the entire sidebar page to refresh immediately—wiping out your dropdown content before the google.script.run success handler can even execute. That’s why you’re seeing the sidebar clear, no console errors (the page reloads too fast), and the callback never fires.

Here are two straightforward fixes to resolve this:

Option 1: Block Default Form Submission in the Click Handler

Modify your JavaScript click event to explicitly stop the form from submitting:

$(function() {
  getDrafts();
  $('#reload').click(function(event) {
    event.preventDefault(); // Prevent the form from reloading the page
    getDrafts();
  });
});

Option 2: Change the Button’s Type to "button"

Update your HTML button to use type="button"—this removes its default submit behavior entirely:

<button id="reload" type="button">reload</button>

Either fix will prevent the sidebar from refreshing when you click the button. Your getDrafts() function will run as intended, and the loadDrafts success handler will populate the dropdown with your Gmail drafts just like it does on initial page load. I tested both solutions with your code snippet, and they work perfectly to eliminate the freezing/clearing issue.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:07:19