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 模式。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-04。
[null,null,["最后更新时间 (UTC):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. |"]]