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

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.

主站蜘蛛池模板: 吴江市| 保靖县| 葵青区| 鄂托克前旗| 晴隆县| 德惠市| 磐石市| 景谷| 仁怀市| 米易县| 淮滨县| 浠水县| 武强县| 师宗县| 芦溪县| 阿瓦提县| 阿合奇县| 西峡县| 额尔古纳市| 都匀市| 武宁县| 南涧| 延津县| 琼中| 霍邱县| 延边| 潍坊市| 三门县| 八宿县| 通化县| 封开县| 和田市| 安阳市| 林芝县| 建阳市| 布拖县| 莱西市| 夏河县| 中西区| 左贡县| 永胜县|