google.script.host
هي واجهة برمجة تطبيقات JavaScript غير متزامنة من جهة العميل ويمكنها التفاعل
مع مربّعات الحوار أو الأشرطة الجانبية في "مستندات Google" أو "جداول بيانات Google" أو "نماذج Google" التي تحتوي على
صفحات خدمة HTML. لتنفيذ الدوال من جهة الخادم من رمز من جهة العميل، استخدِم google.script.run
. للاطّلاع على مزيد من المعلومات، راجِع دليل الاتصال بوظائف الخادم في خدمة HTML.
أماكن إقامة
الموقع | الوصف |
---|---|
origin | يوفّر هذا الخيار نطاق المضيف، لكي تتمكن النصوص البرمجية من ضبط مصدرها بشكلٍ صحيح. |
الطُرق
الطريقة | نوع القيمة التي يتم إرجاعها | وصف قصير |
---|---|---|
close() |
void |
لإغلاق مربع الحوار أو الشريط الجانبي الحالي |
editor.focus() |
void |
لتبديل تركيز المتصفح من مربع الحوار أو الشريط الجانبي إلى أداة تحرير "مستندات Google" أو "جداول بيانات Google" أو "نماذج Google". |
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" أو "جداول بيانات Google" أو "نماذج Google".
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)" />
المَعلمات
الاسم | Type | الوصف |
---|---|---|
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)" />
المَعلمات
الاسم | Type | الوصف |
---|---|---|
width | Integer | العرض الجديد بالبكسل |