Class HtmlService
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
HtmlService
스크립트에서 HTML 및 기타 텍스트 콘텐츠를 반환하는 서비스입니다.
보안상의 고려로 인해 스크립트는 브라우저에 콘텐츠를 직접 반환할 수 없습니다. 대신 악의적인 작업을 실행할 수 없도록 HTML을 정리해야 합니다. 반품할 수 있는 항목에 적용되는 제한사항은 HtmlOutput
의 설명을 참고하세요.
속성
속성 | 유형 | 설명 |
SandboxMode | SandboxMode | 클라이언트 측 HtmlService 스크립트에 사용할 수 있는 샌드박스 모드를 나타내는 enum입니다. |
XFrameOptionsMode | XFrameOptionsMode | 클라이언트 측 HtmlService 스크립트에 사용할 수 있는 X-Frame-Options 모드를 나타내는 enum입니다. |
자세한 문서
createHtmlOutput()
스크립트에서 반환할 수 있는 새 HtmlOutput
객체를 만듭니다.
const output = HtmlService.createHtmlOutput();
리턴
HtmlOutput
- 새 HtmlOutput 객체
createHtmlOutput(blob)
BlobSource
리소스에서 새 HtmlOutput
객체를 만듭니다.
function createFromBlob(blob) {
const output = HtmlService.createHtmlOutput(blob);
return output;
}
매개변수
리턴
HtmlOutput
: 새 HtmlOutput
객체
생성 값
Error
: blob에 HTML이 포함되어 있지 않거나 HTML 형식이 잘못된 경우
createHtmlOutput(html)
스크립트에서 반환할 수 있는 새 HtmlOutput
객체를 만듭니다.
const output = HtmlService.createHtmlOutput('<b>Hello world!</b>');
매개변수
리턴
HtmlOutput
- 새 HtmlOutput 객체
생성 값
Error
: HTML 형식이 잘못된 경우
createHtmlOutputFromFile(filename)
코드 편집기의 파일에서 새 HtmlOutput
객체를 만듭니다.
const output = HtmlService.createHtmlOutputFromFile('myPage');
매개변수
이름 | 유형 | 설명 |
filename | String | 사용할 파일의 이름 |
리턴
HtmlOutput
: 새 HtmlOutput
객체
생성 값
Error
: 파일을 찾을 수 없거나 HTML 형식이 잘못된 경우
createTemplate(blob)
BlobSource
리소스에서 새 HtmlTemplate
객체를 만듭니다.
function createFromBlob(blob) {
const template = HtmlService.createTemplate(blob);
const output = template.evaluate();
return output;
}
매개변수
리턴
HtmlTemplate
: 새 HtmlTemplate
객체
생성 값
Error
: blob에 HTML이 포함되지 않은 경우
createTemplate(html)
스크립트에서 반환할 수 있는 새 HtmlTemplate
객체를 만듭니다.
const template = HtmlService.createTemplate(
'<b>The time is <?= new Date() ?></b>',
);
매개변수
이름 | 유형 | 설명 |
html | String | 템플릿의 콘텐츠 |
리턴
HtmlTemplate
: 새 HtmlTemplate
객체
createTemplateFromFile(filename)
코드 편집기의 파일에서 새 HtmlTemplate
객체를 만듭니다.
const template = HtmlService.createTemplateFromFile('myTemplate');
매개변수
이름 | 유형 | 설명 |
filename | String | 사용할 파일의 이름 |
리턴
HtmlTemplate
: 새 HtmlTemplate
객체
생성 값
Error
: 파일을 찾을 수 없는 경우
getUserAgent()
현재 브라우저의 사용자 에이전트 문자열을 가져옵니다. 웹 앱의 doGet()
또는 doPost()
함수에서 사용되지 않는 경우 대부분의 스크립트 실행에 대해 null
를 반환합니다.
리턴
String
: 사용자 에이전트 문자열
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eHtmlService enables scripts to safely return HTML and other text content to a browser by sanitizing the output to prevent malicious actions.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods to create HTML output from strings, files, or blobs, and supports templates for dynamic content generation.\u003c/p\u003e\n"],["\u003cp\u003eHtmlService provides control over sandbox modes and \u003ccode\u003eX-Frame-Options\u003c/code\u003e for enhanced security.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize HtmlService to build user interfaces and web applications within Google Apps Script.\u003c/p\u003e\n"]]],["HtmlService allows scripts to return sanitized HTML content to browsers, preventing malicious actions. Key actions include creating `HtmlOutput` objects from strings, `BlobSource` resources, or files via `createHtmlOutput()` and `createHtmlOutputFromFile()`. Similarly, `HtmlTemplate` objects can be created using `createTemplate()` and `createTemplateFromFile()` for dynamic content. The `getUserAgent()` method retrieves the current browser's user-agent string. There are `SandboxMode` and `XFrameOptionsMode` properties that can be used for client-side `HtmlService` scripts.\n"],null,["# Class HtmlService\n\nHtmlService\n\nService for returning HTML and other text content from a script.\n\nDue to security considerations, scripts cannot directly return content to a browser. Instead,\nthey must sanitize the HTML so that it cannot perform malicious actions. See the description of\n[HtmlOutput](/apps-script/reference/html/html-output) for what limitations this implies on what can be returned. \n\n### Properties\n\n| Property | Type | Description |\n|---------------------|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|\n| `Sandbox``Mode` | [SandboxMode](/apps-script/reference/html/sandbox-mode) | An enum representing the sandbox modes that can be used for client-side `Html``Service` scripts. |\n| `XFrameOptionsMode` | [XFrameOptionsMode](/apps-script/reference/html/x-frame-options-mode) | An enum representing the `X-Frame-Options` modes that can be used for client-side `Html``Service` scripts. |\n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------------|-----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| [createHtmlOutput()](#createHtmlOutput()) | [HtmlOutput](/apps-script/reference/html/html-output) | Creates a new [HtmlOutput](/apps-script/reference/html/html-output) object that can be returned from the script. |\n| [createHtmlOutput(blob)](#createHtmlOutput(BlobSource)) | [HtmlOutput](/apps-script/reference/html/html-output) | Creates a new [HtmlOutput](/apps-script/reference/html/html-output) object from a [BlobSource](../base/blob-source.html) resource. |\n| [createHtmlOutput(html)](#createHtmlOutput(String)) | [HtmlOutput](/apps-script/reference/html/html-output) | Creates a new [HtmlOutput](/apps-script/reference/html/html-output) object that can be returned from the script. |\n| [createHtmlOutputFromFile(filename)](#createHtmlOutputFromFile(String)) | [HtmlOutput](/apps-script/reference/html/html-output) | Creates a new [HtmlOutput](/apps-script/reference/html/html-output) object from a file in the code editor. |\n| [createTemplate(blob)](#createTemplate(BlobSource)) | [HtmlTemplate](/apps-script/reference/html/html-template) | Creates a new [HtmlTemplate](/apps-script/reference/html/html-template) object from a [BlobSource](../base/blob-source.html) resource. |\n| [createTemplate(html)](#createTemplate(String)) | [HtmlTemplate](/apps-script/reference/html/html-template) | Creates a new [HtmlTemplate](/apps-script/reference/html/html-template) object that can be returned from the script. |\n| [createTemplateFromFile(filename)](#createTemplateFromFile(String)) | [HtmlTemplate](/apps-script/reference/html/html-template) | Creates a new [HtmlTemplate](/apps-script/reference/html/html-template) object from a file in the code editor. |\n| [getUserAgent()](#getUserAgent()) | `String` | Gets the user-agent string for the current browser. |\n\nDetailed documentation\n----------------------\n\n### `create``Html``Output()`\n\nCreates a new [HtmlOutput](/apps-script/reference/html/html-output) object that can be returned from the script.\n\n```javascript\nconst output = HtmlService.createHtmlOutput();\n```\n\n#### Return\n\n\n[HtmlOutput](/apps-script/reference/html/html-output) --- the new HtmlOutput object\n\n*** ** * ** ***\n\n### `create``Html``Output(blob)`\n\nCreates a new [HtmlOutput](/apps-script/reference/html/html-output) object from a [BlobSource](../base/blob-source.html) resource.\n\n```javascript\nfunction createFromBlob(blob) {\n const output = HtmlService.createHtmlOutput(blob);\n return output;\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------------------------------------|-------------------------------|\n| `blob` | [BlobSource](../base/blob-source.html) | the object to get HTML out of |\n\n#### Return\n\n\n[HtmlOutput](/apps-script/reference/html/html-output) --- the new `Html``Output` object\n\n#### Throws\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if the blob doesn't contain HTML or the HTML is malformed\n\n*** ** * ** ***\n\n### `create``Html``Output(html)`\n\nCreates a new [HtmlOutput](/apps-script/reference/html/html-output) object that can be returned from the script.\n\n```javascript\nconst output = HtmlService.createHtmlOutput('\u003cb\u003eHello world!\u003c/b\u003e');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|----------------------|\n| `html` | `String` | the content to serve |\n\n#### Return\n\n\n[HtmlOutput](/apps-script/reference/html/html-output) --- the new HtmlOutput object\n\n#### Throws\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if the html is malformed\n\n*** ** * ** ***\n\n### `create``Html``Output``From``File(filename)`\n\nCreates a new [HtmlOutput](/apps-script/reference/html/html-output) object from a file in the code editor.\n\n```javascript\nconst output = HtmlService.createHtmlOutputFromFile('myPage');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|-----------------------------|\n| `filename` | `String` | the name of the file to use |\n\n#### Return\n\n\n[HtmlOutput](/apps-script/reference/html/html-output) --- the new `Html``Output` object\n\n#### Throws\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if the file wasn't found or the HTML in it is malformed\n\n*** ** * ** ***\n\n### `create``Template(blob)`\n\nCreates a new [HtmlTemplate](/apps-script/reference/html/html-template) object from a [BlobSource](../base/blob-source.html) resource.\n\n```javascript\nfunction createFromBlob(blob) {\n const template = HtmlService.createTemplate(blob);\n const output = template.evaluate();\n return output;\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------------------------------------|--------------------------------|\n| `blob` | [BlobSource](../base/blob-source.html) | The object to get HTML out of. |\n\n#### Return\n\n\n[HtmlTemplate](/apps-script/reference/html/html-template) --- the new `Html``Template` object\n\n#### Throws\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if the blob doesn't contain HTML\n\n*** ** * ** ***\n\n### `create``Template(html)`\n\nCreates a new [HtmlTemplate](/apps-script/reference/html/html-template) object that can be returned from the script.\n\n```javascript\nconst template = HtmlService.createTemplate(\n '\u003cb\u003eThe time is <?= new Date() ?>\u003c/b\u003e',\n);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|-----------------------------|\n| `html` | `String` | the content of the template |\n\n#### Return\n\n\n[HtmlTemplate](/apps-script/reference/html/html-template) --- the new `Html``Template` object\n\n*** ** * ** ***\n\n### `create``Template``From``File(filename)`\n\nCreates a new [HtmlTemplate](/apps-script/reference/html/html-template) object from a file in the code editor.\n\n```javascript\nconst template = HtmlService.createTemplateFromFile('myTemplate');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|-----------------------------|\n| `filename` | `String` | the name of the file to use |\n\n#### Return\n\n\n[HtmlTemplate](/apps-script/reference/html/html-template) --- the new `Html``Template` object\n\n#### Throws\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if the file wasn't found\n\n*** ** * ** ***\n\n### `get``User``Agent()`\n\nGets the user-agent string for the current browser. Returns `null` for most script\nexecutions if not used in a web app's `do``Get()` or `do``Post()` function.\n\n#### Return\n\n\n`String` --- the user-agent string"]]