Enum SandboxMode
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
โหมดแซนด์บ็อกซ์
การแจงนับที่แสดงโหมดแซนด์บ็อกซ์ที่ใช้กับสคริปต์ฝั่งไคลเอ็นต์ HtmlService
ได้ เข้าถึงค่าเหล่านี้ได้จาก HtmlService.SandboxMode
และตั้งค่าได้โดยการเรียกใช้
HtmlOutput.setSandboxMode(mode)
หากต้องการเรียกใช้ Enum ให้เรียกใช้คลาสหลัก ชื่อ และพร็อพเพอร์ตี้ของ Enum เช่น
HtmlService.SandboxMode.IFRAME
โหมด NATIVE
และ EMULATED
เลิกใช้งานเมื่อวันที่ 13 ตุลาคม 2015 และทั้ง 2 โหมดนี้ปิดตัวลงแล้ว ตอนนี้ระบบรองรับเฉพาะโหมด IFRAME
โค้ดฝั่งไคลเอ็นต์ที่แสดงจาก
บริการ HTML จะทำงานในแซนด์บ็อกซ์ด้านความปลอดภัยที่กำหนดข้อจำกัดในโค้ด เพื่อปกป้องผู้ใช้จากการแสดง HTML หรือ JavaScript ที่เป็นอันตราย เมธอด
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 5 โดยใช้เฉพาะฟีเจอร์ที่มีใน ECMAScript 3 โหมดนี้เป็นค่าเริ่มต้นก่อนเดือนกุมภาพันธ์ 2014
EMULATED หยุดให้บริการตั้งแต่วันที่ 10 ธันวาคม
2015 ตอนนี้สคริปต์ทั้งหมดที่พยายามใช้ EMULATED จะใช้ IFRAME แทน
|
IFRAME | Enum | โหมดแซนด์บ็อกซ์ที่ใช้แซนด์บ็อกซ์ iframe แทนเทคโนโลยีแซนด์บ็อกซ์ Caja ที่ใช้ในโหมด EMULATED และ NATIVE โหมดนี้เป็นค่าเริ่มต้นสำหรับสคริปต์ใหม่ตั้งแต่วันที่ 12 พฤศจิกายน 2015 และสำหรับสคริปต์ทั้งหมดตั้งแต่วันที่ 6 กรกฎาคม 2016
โหมดนี้มีข้อจำกัดน้อยกว่าโหมดแซนด์บ็อกซ์อื่นๆ มากและทำงานได้เร็วที่สุด แต่
ไม่ทำงานเลยในเบราว์เซอร์รุ่นเก่าบางรุ่น รวมถึง Internet Explorer 9
|
NATIVE | Enum | โหมดแซนด์บ็อกซ์ที่สร้างขึ้นบนโหมดเข้มงวดของ ECMAScript 5 โหมดแซนด์บ็อกซ์ที่สร้างขึ้นบน
โหมดเข้มงวดของ ECMAScript 5 เราได้หยุดให้บริการโหมดนี้
ตั้งแต่วันที่ 6 กรกฎาคม 2016 ตอนนี้สคริปต์ทั้งหมดใช้โหมด IFRAME |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-04 UTC
[null,null,["อัปเดตล่าสุด 2025-08-04 UTC"],[[["\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. |"]]