google.script.host
یک API جاوا اسکریپت سمت کلاینت ناهمزمان است که میتواند با دیالوگها یا نوارهای فرعی در Google Docs، Sheets یا Forms که حاوی صفحات سرویس HTML هستند تعامل داشته باشد. برای اجرای توابع سمت سرور از کد سمت سرویس گیرنده، از google.script.run
استفاده کنید. برای اطلاعات بیشتر به راهنمای ارتباط با توابع سرور در سرویس HTML مراجعه کنید.
خواص
ویژگی | شرح |
---|---|
origin | دامنه میزبان را فراهم می کند، بنابراین اسکریپت ها می توانند مبدا خود را به درستی تنظیم کنند. |
مواد و روش ها
روش | نوع برگشت | توضیح مختصر |
---|---|---|
close() | void | گفتگو یا نوار کناری فعلی را می بندد. |
editor.focus() | void | فوکوس مرورگر را از کادر گفتگو یا نوار کناری به ویرایشگر Google Docs، Sheets یا Forms تغییر میدهد. |
setHeight(height) | void | ارتفاع گفتگوی فعلی را تنظیم می کند. |
setWidth(width) | void | عرض گفتگوی فعلی را تنظیم می کند. |
مستندات دقیق
close()
گفتگو یا نوار کناری فعلی را می بندد.
Code.gs
function onOpen(e) { SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .createMenu('Sidebar').addItem('Show', 'showSidebar').addToUi(); } function showSidebar() { var html = HtmlService.createHtmlOutputFromFile('Index'); SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .showSidebar(html); }
Index.html
<input type="button" value="Close" onclick="google.script.host.close()" />
editor.focus()
فوکوس مرورگر را از کادر گفتگو یا نوار کناری به ویرایشگر Google Docs، Sheets یا Forms تغییر میدهد.
Code.gs
function onOpen(e) { SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .createMenu('Sidebar').addItem('Show', 'showSidebar').addToUi(); } function showSidebar() { var html = HtmlService.createHtmlOutputFromFile('Index'); SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .showSidebar(html); }
Index.html
<input type="button" value="Switch focus" onclick="google.script.host.editor.focus()" />
setHeight(height)
ارتفاع گفتگوی فعلی را تنظیم می کند.
Code.gs
function onOpen(e) { SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .createMenu('Dialog').addItem('Show', 'showDialog').addToUi(); } function showDialog() { var html = HtmlService.createHtmlOutputFromFile('Index') .setWidth(300) .setHeight(200); SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .showModalDialog(html, 'Dialog title'); }
Index.html
<script> function resizeDialog(width, height) { google.script.host.setWidth(width); google.script.host.setHeight(height); } </script> <input type="button" value="Resize dialog" onclick="resizeDialog(450, 300)" />
مولفه های
نام | تایپ کنید | شرح |
---|---|---|
height | Integer | ارتفاع جدید، بر حسب پیکسل |
setWidth(width)
عرض گفتگوی فعلی را تنظیم می کند.
Code.gs
function onOpen(e) { SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .createMenu('Dialog').addItem('Show', 'showDialog').addToUi(); } function showDialog() { var html = HtmlService.createHtmlOutputFromFile('Index') .setWidth(300) .setHeight(200); SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .showModalDialog(html, 'Dialog title'); }
Index.html
<script> function resizeDialog(width, height) { google.script.host.setWidth(width); google.script.host.setHeight(height); } </script> <input type="button" value="Resize dialog" onclick="resizeDialog(450, 300)" />
مولفه های
نام | تایپ کنید | شرح |
---|---|---|
width | Integer | عرض جدید، بر حسب پیکسل |