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

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.

主站蜘蛛池模板: 界首市| 青冈县| 桂阳县| 江城| 抚顺县| 昌宁县| 井陉县| 新泰市| 肥东县| 襄城县| 明光市| 沧源| 佛冈县| 吉安县| 霍州市| 股票| 龙胜| 隆昌县| 屏东县| 文成县| 登封市| 尚义县| 民县| 喀什市| 禹城市| 子洲县| 涟水县| 龙州县| 芒康县| 安阳县| 溆浦县| 郴州市| 元谋县| 温州市| 塔河县| 鄯善县| 沂南县| 淅川县| 绍兴市| 贵溪市| 舒兰市|