Enum SandboxMode
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
沙箱模式
列舉,代表可用於用戶端 HtmlService
指令碼的沙箱模式。這些值可從 HtmlService.SandboxMode
存取,並透過呼叫 HtmlOutput.setSandboxMode(mode)
設定。
如要呼叫列舉,請呼叫其父項類別、名稱和屬性。例如
HtmlService.SandboxMode.IFRAME
。
NATIVE
和 EMULATED
模式已於
2015 年 10 月 13 日淘汰,目前已全面停用。目前僅支援 IFRAME
模式。
為保護使用者免於惡意 HTML 或 JavaScript 侵害,HTML 服務提供的用戶端程式碼會在安全沙箱中執行,並對程式碼施加限制。這個方法先前可讓指令碼作者選擇不同版本的沙箱,但現在已無效。HtmlOutput.setSandboxMode(mode)
詳情請參閱 HTML 服務限制指南。
IFRAME
模式的限制比其他沙箱模式少很多,執行速度也最快,但完全不支援某些舊版瀏覽器,包括 Internet Explorer 9。您也可以檢查 google.script.sandbox.mode
,在用戶端指令碼中讀取沙箱模式。請注意,這項屬性會傳回用戶端上的實際模式,如果使用者的瀏覽器不支援要求的模式,則可能與伺服器上要求的模式不同。
<!-- Read the sandbox mode (in a client-side script). -->
<script>
alert(google.script.sandbox.mode);
</script>
屬性
屬性 | 類型 | 說明 |
EMULATED | Enum | 舊版沙箱模式,僅使用 ECMAScript 3 中提供的功能,模擬 ECMAScript 5 嚴格模式。2014 年 2 月前,這是預設模式。
EMULATED 已於 2015 年 12 月 10 日終止服務。所有嘗試使用 EMULATED 的指令碼現在都會改用 IFRAME 。
|
IFRAME | Enum | 沙箱模式,使用 iframe 沙箱,而非 EMULATED 和 NATIVE 模式使用的 Caja 沙箱技術。自 2015 年 11 月 12 日起,新指令碼預設會採用這個模式;自 2016 年 7 月 6 日起,所有指令碼都會採用這個模式。
這個模式的限制比其他沙箱模式少很多,執行速度也最快,但完全不支援某些舊版瀏覽器,包括 Internet Explorer 9。
|
NATIVE | Enum | 以 ECMAScript 5 嚴格模式為基礎的沙箱模式。以 ECMAScript 5 嚴格模式為基礎建構的沙箱模式。這項模式已於 2016 年 7 月 6 日停用。所有指令碼現在都使用 IFRAME 模式。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-04 (世界標準時間)。
[null,null,["上次更新時間:2025-08-04 (世界標準時間)。"],[[["\u003cp\u003eSandboxMode is used for setting the sandbox environment for client-side HtmlService scripts in Google Apps Script.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eIFRAME\u003c/code\u003e is the only supported SandboxMode; \u003ccode\u003eNATIVE\u003c/code\u003e and \u003ccode\u003eEMULATED\u003c/code\u003e are deprecated and sunset.\u003c/p\u003e\n"],["\u003cp\u003eClient-side code in HTML service runs in a security sandbox with restrictions to protect users.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eIFRAME\u003c/code\u003e mode has fewer restrictions and runs faster but might not work in older browsers like Internet Explorer 9.\u003c/p\u003e\n"],["\u003cp\u003eYou can read the actual sandbox mode on the client-side using \u003ccode\u003egoogle.script.sandbox.mode\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Enum SandboxMode\n\nSandboxMode\n\nAn enum representing the sandbox modes that can be used for client-side [HtmlService](/apps-script/reference/html/html-service)\nscripts. These values can be accessed from [HtmlService.SandboxMode](/apps-script/reference/html/html-service#SandboxMode), and set by calling\n[HtmlOutput.setSandboxMode(mode)](/apps-script/reference/html/html-output#setSandboxMode(SandboxMode)).\n\nTo call an enum, you call its parent class, name, and property. For example, `\nHtmlService.SandboxMode.IFRAME`.\n\nThe `NATIVE` and `EMULATED` modes were [deprecated on October 13, 2015](https://workspace.google.com/blog/product-announcements/google-apps-script-update-htmlservice) and both are now sunset. Only `IFRAME` mode is now\nsupported.\n\nTo protect users from being served malicious HTML or JavaScript, client-side code served from\nHTML service executes in a security sandbox that imposes restrictions on the code. The method\n[HtmlOutput.setSandboxMode(mode)](/apps-script/reference/html/html-output#setSandboxMode(SandboxMode)) previously allowed script authors to choose\nbetween different versions of the sandbox, but now has no effect. For more information, see the\n[guide to restrictions in HTML service](/apps-script/guides/html/restrictions).\n\nThe `IFRAME` mode imposes many fewer restrictions than the other sandbox modes and runs\nfastest, but does not work at all in certain older browsers, including Internet Explorer 9. The\nsandbox mode can also be read in a client-side script by inspecting `google.script.sandbox.mode`. Note that this property returns the actual mode on the client, which\nmay differ from the mode requested on the server if the requested mode is not supported in the\nuser's browser.\n\n```html\n\u003c!-- Read the sandbox mode (in a client-side script). --\u003e\n\u003cscript\u003e\n alert(google.script.sandbox.mode);\n\u003c/script\u003e\n``` \n\n### Properties\n\n| Property | Type | Description |\n|------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `EMULATED` | `Enum` | A legacy sandbox mode that emulates ECMAScript 5 strict mode using only the features available in ECMAScript 3. This mode was the default prior to February 2014. `EMULATED` was [sunset as of December 10, 2015](/apps-script/guides/support/sunset). All scripts attempting use `EMULATED` will now use `IFRAME` instead. |\n| `IFRAME` | `Enum` | A sandbox mode that uses iframe sandboxing instead of the Caja sandbox technology used by the `EMULATED` and `NATIVE` modes. This mode is the default for new scripts as of November 12, 2015 and for all scripts as of July 6, 2016. This mode imposes many fewer restrictions than the other sandbox modes and runs fastest, but does not work at all in certain older browsers, including Internet Explorer 9. |\n| `NATIVE` | `Enum` | A sandbox mode that is built on top of ECMAScript 5 strict mode. A sandbox mode built on top of ECMAScript 5 strict mode. This mode was [sunset as of July 6, 2016](/apps-script/guides/support/sunset). All scripts now use `IFRAME` mode. |"]]