Google Apps Script

Class HtmlService

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 of HtmlOutput for what limitations this implies on what can be returned.

Properties

PropertyTypeDescription
SandboxModeSandboxModeAn enum representing the ECMAScript sandbox modes that can be used for client-side HTML service scripts.

Methods

MethodReturn typeBrief description
createHtmlOutput()HtmlOutputCreates a new HtmlOutput object that can be returned from the script.
createHtmlOutput(blob)HtmlOutputCreates a new HtmlOutput object from a BlobSource resource.
createHtmlOutput(html)HtmlOutputCreates a new HtmlOutput object that can be returned from the script.
createHtmlOutputFromFile(filename)HtmlOutputCreates a new HtmlOutput object from a file in the code editor.
createTemplate(blob)HtmlTemplateCreates a new HtmlTemplate object from a BlobSource resource.
createTemplate(html)HtmlTemplateCreates a new HtmlTemplate object that can be returned from the script.
createTemplateFromFile(filename)HtmlTemplateCreates a new HtmlTemplate object from a file in the code editor.

Detailed documentation

createHtmlOutput()

Creates a new HtmlOutput object that can be returned from the script.

 
var output = HtmlService.createHtmlOutput();
 

Return

HtmlOutput — the new HtmlOutput object


createHtmlOutput(blob)

Creates a new HtmlOutput object from a BlobSource resource.

 
function createFromBlob(blob) {
   var output = HtmlService.createHtmlOutput(blob);
   return output;
 }
 

Parameters

NameTypeDescription
blobBlobSourcethe object to get HTML out of

Return

HtmlOutput — the new HtmlOutput object


createHtmlOutput(html)

Creates a new HtmlOutput object that can be returned from the script.

 
var output = HtmlService.createHtmlOutput('<b>Hello world!</b>');
 

Parameters

NameTypeDescription
htmlStringthe content to serve

Return

HtmlOutput — the new HtmlOutput object


createHtmlOutputFromFile(filename)

Creates a new HtmlOutput object from a file in the code editor.

 
var output = HtmlService.createHtmlOutputFromFile('myPage');
 

Parameters

NameTypeDescription
filenameStringthe name of the file to use

Return

HtmlOutput — the new HtmlOutput object


createTemplate(blob)

Creates a new HtmlTemplate object from a BlobSource resource.

 
function createFromBlob(blob) {
   var template = HtmlService.createTemplate(blob);
   return output;
 }
 

Parameters

NameTypeDescription
blobBlobSourcethe object to get HTML out of

Return

HtmlTemplate — the new HtmlTemplate object


createTemplate(html)

Creates a new HtmlTemplate object that can be returned from the script.

 
var template = HtmlService.createTemplate('<b>The time is &lt;?= new Date() ?&gt;</b>');
 

Parameters

NameTypeDescription
htmlStringthe content of the template

Return

HtmlTemplate — the new HtmlTemplate object


createTemplateFromFile(filename)

Creates a new HtmlTemplate object from a file in the code editor.

 
var template = HtmlService.createTemplateFromFile('myTemplate');
 

Parameters

NameTypeDescription
filenameStringthe name of the file to use

Return

HtmlTemplate — the new HtmlTemplate object

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.