HTML Service

HTML

This service allows Apps Script applications to return HTML, usually as a user interface. If you're new to using this class, we recommend you also see theguide to Html Service

.

Classes

NameBrief description
HtmlOutputAnHtmlOutput object that can be served from a script.
HtmlOutputMetaTagAn object that represents a meta tag added to the page by callingHtmlOutput.addMetaTag(name, content).
HtmlServiceService for returning HTML and other text content from a script.
HtmlTemplateA template object for dynamically constructing HTML.
SandboxModeAn enum representing the sandbox modes that can be used for client-sideHtmlServicescripts.
XFrameOptionsModeAn enum representing theX-Frame-Options modes that can be used for client-sideHtmlService scripts.

HtmlOutput

Methods

MethodReturn typeBrief description
addMetaTag(name, content)HtmlOutputAdds a meta tag to the page.
append(addedContent)HtmlOutputAppends new content to the content of thisHtmlOutput.
appendUntrusted(addedContent)HtmlOutputAppends new content to the content of thisHtmlOutput, using contextual escaping.
asTemplate()HtmlTemplateReturns anHtmlTemplate backed by thisHtmlOutput.
clear()HtmlOutputClears the current content.
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBlob()BlobReturn the data inside this object as a blob.
getContent()StringGets the content of thisHtmlOutput.
getFaviconUrl()StringGets the URL for a favicon link tag added to the page by callingsetFaviconUrl(iconUrl).
getHeight()IntegerGets the initial height of thecustom dialog in GoogleDocs, Sheets, or Forms.
getMetaTags()HtmlOutputMetaTag[]Gets an array of objects that represent meta tags added to the page by callingaddMetaTag(name, content).
getTitle()StringGets the title of the output page.
getWidth()IntegerGets the initial width of thecustom dialog in GoogleDocs, Sheets, or Forms.
setContent(content)HtmlOutputSets the content of thisHtmlOutput.
setFaviconUrl(iconUrl)HtmlOutputAdds a link tag for a favicon to the page.
setHeight(height)HtmlOutputSets the initial height of thecustom dialog in GoogleDocs, Sheets, or Forms.
setSandboxMode(mode)HtmlOutputThis method now has no effect — previously it set thesandboxmode used for client-side scripts.
setTitle(title)HtmlOutputSets the title of the output page.
setWidth(width)HtmlOutputSets the initial width of acustom dialog in GoogleDocs, Sheets, or Forms.
setXFrameOptionsMode(mode)HtmlOutputSets the state of the page'sX-Frame-Options header, which controls clickjackingprevention.

HtmlOutputMetaTag

Methods

MethodReturn typeBrief description
getContent()StringGets the content of this meta tag.
getName()StringGets the name of thisHtmlOutputMetaTag.

HtmlService

Properties

PropertyTypeDescription
SandboxModeSandboxModeAn enum representing the sandbox modes that can be used for client-sideHtmlServicescripts.
XFrameOptionsModeXFrameOptionsModeAn enum representing theX-Frame-Options modes that can be used for client-sideHtmlService scripts.

Methods

MethodReturn typeBrief description
createHtmlOutput()HtmlOutputCreates a newHtmlOutput object that can be returned from the script.
createHtmlOutput(blob)HtmlOutputCreates a newHtmlOutput object from aBlobSource resource.
createHtmlOutput(html)HtmlOutputCreates a newHtmlOutput object that can be returned from the script.
createHtmlOutputFromFile(filename)HtmlOutputCreates a newHtmlOutput object from a file in the code editor.
createTemplate(blob)HtmlTemplateCreates a newHtmlTemplate object from aBlobSource resource.
createTemplate(html)HtmlTemplateCreates a newHtmlTemplate object that can be returned from the script.
createTemplateFromFile(filename)HtmlTemplateCreates a newHtmlTemplate object from a file in the code editor.
getUserAgent()StringGets the user-agent string for the current browser.

HtmlTemplate

Methods

MethodReturn typeBrief description
evaluate()HtmlOutputEvaluates this template and returns anHtmlOutput object.
getCode()StringGenerates a string of JavaScript code, based on the template file, that can be evaluated.
getCodeWithComments()StringGenerates a string of JavaScript code that can be evaluated, with each line of the codecontaining the original line from the template as a comment.
getRawContent()StringReturns the unprocessed content of this template.

SandboxMode

Properties

PropertyTypeDescription
EMULATEDEnumA legacy sandbox mode that emulates ECMAScript 5 strict mode using only the features availablein ECMAScript 3.
IFRAMEEnumA sandbox mode that uses iframe sandboxing instead of the Caja sandbox technology used by theEMULATED andNATIVE modes.
NATIVEEnumA sandbox mode that is built on top of ECMAScript 5 strict mode.

XFrameOptionsMode

Properties

PropertyTypeDescription
ALLOWALLEnumNoX-Frame-Options header will be set.
DEFAULTEnumSets the default value for theX-Frame-Options header, which preserves normal securityassumptions.

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.