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

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.

主站蜘蛛池模板: 永顺县| 泰安市| 蕲春县| 新沂市| 兴安县| 潮安县| 托克逊县| 濮阳市| 彭山县| 青川县| 陆川县| 新津县| 县级市| 合江县| 遂溪县| 黄石市| 乐安县| 迁安市| 塔城市| 临潭县| 博白县| 闸北区| 沙田区| 丰城市| 阜康市| 孟州市| 隆子县| 焦作市| 且末县| 新密市| 公主岭市| 丽江市| 兴义市| 如东县| 从化市| 邯郸市| 灌南县| 光泽县| 竹北市| 调兵山市| 大冶市|