क्लास google.script.host (क्लाइंट-साइड एपीआई)

google.script.host एक एसिंक्रोनस क्लाइंट-साइड JavaScript API है, जो Google Docs, Sheets या Forms में डायलॉग या साइडबार के साथ, जिनमें यह शामिल हो एचटीएमएल-सेवा पेज. यहां दिए गए तरीके से, सर्वर साइड फ़ंक्शन एक्ज़ीक्यूट करने के लिए क्लाइंट-साइड कोड मौजूद है, तो google.script.run का इस्तेमाल करें. ज़्यादा जानकारी के लिए, यह देखें यह सर्वर के फ़ंक्शन के साथ कम्यूनिकेट करने की गाइड HTML सेवा में.

प्रॉपर्टी

प्रॉपर्टीब्यौरा
originयह होस्ट डोमेन उपलब्ध कराता है, ताकि स्क्रिप्ट ऑरिजिन सही है.

तरीके

तरीकारिटर्न टाइपसंक्षिप्त विवरण
close() void इससे मौजूदा डायलॉग या साइडबार बंद हो जाता है.
editor.focus() void ब्राउज़र के फ़ोकस को डायलॉग या साइडबार से Google Docs, Sheets या Forms एडिटर पर स्विच करता है.
setHeight(height) void मौजूदा डायलॉग की ऊंचाई सेट करता है.
setWidth(width) void मौजूदा डायलॉग की चौड़ाई सेट करता है.

विस्तृत दस्तावेज़

close()

इससे मौजूदा डायलॉग या साइडबार बंद हो जाता है.

Code.gsIndex.html
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);
}
<input type="button" value="Close"
 
onclick="google.script.host.close()" />

editor.focus()

ब्राउज़र के फ़ोकस को डायलॉग या साइडबार से Google Docs, Sheets या Forms एडिटर पर स्विच करता है.

Code.gsIndex.html
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);
}
<input type="button" value="Switch focus"
 
onclick="google.script.host.editor.focus()" />

setHeight(height)

मौजूदा डायलॉग की ऊंचाई सेट करता है.

Code.gsIndex.html
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');
}
<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)" />

पैरामीटर

नामटाइपब्यौरा
heightIntegerपिक्सल में नई ऊंचाई

setWidth(width)

मौजूदा डायलॉग की चौड़ाई सेट करता है.

Code.gsIndex.html
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');
}
<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)" />

पैरामीटर

नामटाइपब्यौरा
widthIntegerपिक्सल में नई चौड़ाई