google.script.host
, Google Dokümanlar, E-Tablolar veya Formlar'da HTML hizmeti sayfaları içeren iletişim kutuları ya da kenar çubuklarıyla etkileşimde bulunabilen, eşzamansız bir istemci tarafı JavaScript API'sidir. İstemci tarafı koddan sunucu tarafı işlevleri yürütmek için google.script.run
kullanın. Daha fazla bilgi için HTML hizmetinde sunucu işlevleriyle iletişim kurma kılavuzuna bakın.
Özellikler
Özellik | Açıklama |
---|---|
origin | Komut dosyalarının kaynaklarını doğru şekilde ayarlayabilmesi için ana makine alan adını sağlar. |
Yöntemler
Yöntem | Dönüş türü | Kısa açıklama |
---|---|---|
close() |
void |
Mevcut iletişim kutusunu veya kenar çubuğunu kapatır. |
editor.focus() |
void |
Tarayıcı odağını iletişim kutusundan veya kenar çubuğundan Google Dokümanlar, E-Tablolar veya Formlar düzenleyicisine geçirir. |
setHeight(height) |
void |
Geçerli iletişim kutusunun yüksekliğini ayarlar. |
setWidth(width) |
void |
Geçerli iletişim kutusunun genişliğini ayarlar. |
Ayrıntılı belgeler
close()
Mevcut iletişim kutusunu veya kenar çubuğunu kapatır.
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()
Tarayıcı odağını iletişim kutusundan veya kenar çubuğundan Google Dokümanlar, E-Tablolar veya Formlar düzenleyicisine geçirir.
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)
Geçerli iletişim kutusunun yüksekliğini ayarlar.
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)" />
Parametreler
Ad | Tür | Açıklama |
---|---|---|
height | Integer | piksel cinsinden yeni yükseklik |
setWidth(width)
Geçerli iletişim kutusunun genişliğini ayarlar.
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)" />
Parametreler
Ad | Tür | Açıklama |
---|---|---|
width | Integer | piksel cinsinden yeni genişlik |