官术网_书友最值得收藏!

Creating a sidebar

A sidebar is a static dialog box and is included on the right-hand side of the document editor window. To create a sidebar, type the following code in the editor:

function onOpen() {
  var htmlOutput = HtmlService
  .createHtmlOutput('<button onclick="alert(\'Hello World!\');">Click Me</button>')
  .setTitle('My Sidebar');

  DocumentApp.getUi().showSidebar(htmlOutput);
}

In the preceding code, you are using HtmlService and invoking its method createHtmlOutput then consecutively invoking the setTitle method. To test this code, run the onOpen function or reload the document. The sidebar will open in the right-hand side of the document window as shown in the following screenshot. The sidebar layout size is a fixed one, which means you cannot change, alter, or resize it.

The button in the sidebar is an HTML element, not a GAS element, and if clicked, it opens the browser interface's alert box.

主站蜘蛛池模板: 湾仔区| 洛川县| 兴宁市| 仙桃市| 绍兴市| 曲靖市| 铜梁县| 祁连县| 肥西县| 什邡市| 会东县| 娱乐| 张掖市| 乌拉特前旗| 应城市| 邹平县| 黔西| 翁牛特旗| 井冈山市| 金塔县| 沭阳县| 寿宁县| 上饶市| 钦州市| 徐闻县| 大足县| 定边县| 特克斯县| 新密市| 揭阳市| 托克托县| 康定县| 布尔津县| 建宁县| 昭通市| 连城县| 黄浦区| 墨玉县| 泗水县| 玉山县| 天门市|