google.script.host
, एसिंक्रोनस क्लाइंट-साइड JavaScript API है. यह Google Docs, Sheets या Forms में ऐसे डायलॉग या साइडबार के साथ इंटरैक्ट कर सकता है जिनमें एचटीएमएल सेवा वाले पेज शामिल होते हैं. क्लाइंट-साइड कोड की मदद से सर्वर-साइड फ़ंक्शन चलाने के लिए, google.script.run
का इस्तेमाल करें. ज़्यादा जानकारी के लिए, एचटीएमएल सेवा में,
सर्वर फ़ंक्शन का इस्तेमाल करने से जुड़ी गाइड
देखें.
प्रॉपर्टी
प्रॉपर्टी | ब्यौरा |
---|---|
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)" />
पैरामीटर
नाम | 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 | नई चौड़ाई, पिक्सल में |