Class HtmlService Stay organized with collections Save and categorize content based on your preferences.
Service for returning HTML and other text content from a script.
Due to security considerations, scripts cannot directly return content to a browser. Instead,they must sanitize the HTML so that it cannot perform malicious actions. See the description ofHtml
for what limitations this implies on what can be returned.
Properties
Property | Type | Description |
---|---|---|
Sandbox | Sandbox | An enum representing the sandbox modes that can be used for client-sideHtml scripts. |
XFrameOptionsMode | XFrameOptionsMode | An enum representing theX-Frame-Options modes that can be used for client-sideHtml scripts. |
Methods
Method | Return type | Brief description |
---|---|---|
create | Html | Creates a newHtml object that can be returned from the script. |
create | Html | Creates a newHtml object from aBlob resource. |
create | Html | Creates a newHtml object that can be returned from the script. |
create | Html | Creates a newHtml object from a file in the code editor. |
create | Html | Creates a newHtml object from aBlob resource. |
create | Html | Creates a newHtml object that can be returned from the script. |
create | Html | Creates a newHtml object from a file in the code editor. |
get | String | Gets the user-agent string for the current browser. |
Detailed documentation
createHtmlOutput()
Creates a newHtml
object that can be returned from the script.
constoutput=HtmlService.createHtmlOutput();
Return
Html
— the new HtmlOutput object
createHtmlOutput(blob)
Creates a newHtml
object from aBlob
resource.
functioncreateFromBlob(blob){constoutput=HtmlService.createHtmlOutput(blob);returnoutput;}
Parameters
Name | Type | Description |
---|---|---|
blob | Blob | the object to get HTML out of |
Return
Html
— the newHtml
object
Throws
Error
— if the blob doesn't contain HTML or the HTML is malformed
createHtmlOutput(html)
Creates a newHtml
object that can be returned from the script.
constoutput=HtmlService.createHtmlOutput('<b>Hello world!</b>');
Parameters
Name | Type | Description |
---|---|---|
html | String | the content to serve |
Return
Html
— the new HtmlOutput object
Throws
Error
— if the html is malformed
createHtmlOutputFromFile(filename)
Creates a newHtml
object from a file in the code editor.
constoutput=HtmlService.createHtmlOutputFromFile('myPage');
Parameters
Name | Type | Description |
---|---|---|
filename | String | the name of the file to use |
Return
Html
— the newHtml
object
Throws
Error
— if the file wasn't found or the HTML in it is malformed
createTemplate(blob)
Creates a newHtml
object from aBlob
resource.
functioncreateFromBlob(blob){consttemplate=HtmlService.createTemplate(blob);constoutput=template.evaluate();returnoutput;}
Parameters
Name | Type | Description |
---|---|---|
blob | Blob | The object to get HTML out of. |
Return
Html
— the newHtml
object
Throws
Error
— if the blob doesn't contain HTML
createTemplate(html)
Creates a newHtml
object that can be returned from the script.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);
Parameters
Name | Type | Description |
---|---|---|
html | String | the content of the template |
Return
Html
— the newHtml
object
createTemplateFromFile(filename)
Creates a newHtml
object from a file in the code editor.
consttemplate=HtmlService.createTemplateFromFile('myTemplate');
Parameters
Name | Type | Description |
---|---|---|
filename | String | the name of the file to use |
Return
Html
— the newHtml
object
Throws
Error
— if the file wasn't found
getUserAgent()
Gets the user-agent string for the current browser. Returnsnull
for most scriptexecutions if not used in a web app'sdo
ordo
function.
Return
String
— the user-agent string
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-03 UTC.