- Learning Google Apps Script
- Ramalingam Ganapathy
- 135字
- 2021-07-16 12:40:04
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.
推薦閱讀
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- Instant Typeahead.js
- Python Data Analysis(Second Edition)
- OpenGL Data Visualization Cookbook
- ArcGIS for Desktop Cookbook
- Scratch趣味編程:陪孩子像搭積木一樣學編程
- Vue.js 3應用開發與核心源碼解析
- Building Slack Bots
- Python機器學習開發實戰
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Visual FoxPro程序設計實驗教程
- HTML5程序開發范例寶典
- C# 10核心技術指南
- 大話程序員:從入門到優秀全攻略
- 虛擬現實:引領未來的人機交互革命