HTML <iframe> แอตทริบิวต์แซนด์บ็อกซ์
ตัวอย่าง
<iframe> ที่มีข้อจำกัดพิเศษ:
<iframe src="demo_iframe_sandbox.htm" sandbox></iframe>
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
แอตทริบิวต์sandbox
เปิดใช้งานชุดข้อจำกัดเพิ่มเติมสำหรับเนื้อหาใน iframe
เมื่อsandbox
แอตทริบิวต์มีอยู่ และจะ:
- ถือว่าเนื้อหามาจากแหล่งกำเนิดที่ไม่เหมือนใคร
- การส่งแบบฟอร์มบล็อก
- บล็อกการดำเนินการสคริปต์
- ปิดการใช้งาน APIs
- ป้องกันไม่ให้ลิงก์กำหนดเป้าหมายบริบทการสืบค้นอื่น ๆ
- ป้องกันเนื้อหาจากการใช้ปลั๊กอิน (ผ่าน
<embed>
,<object>
,<applet>
, หรืออื่นๆ) - ป้องกันเนื้อหาเพื่อนำทางบริบทการสืบค้นระดับบนสุด
- บล็อกคุณสมบัติที่ทริกเกอร์โดยอัตโนมัติ (เช่น เล่นวิดีโอโดยอัตโนมัติหรือเน้นการควบคุมแบบฟอร์มโดยอัตโนมัติ)
ค่าของsandbox
แอตทริบิวต์สามารถเป็นค่าว่างได้ (จากนั้นจึงใช้ข้อจำกัดทั้งหมด) หรือรายการค่าที่กำหนดไว้ล่วงหน้าที่คั่นด้วยช่องว่างซึ่งจะลบข้อจำกัดเฉพาะ
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนแอตทริบิวต์อย่างเต็มที่
Attribute | |||||
---|---|---|---|---|---|
sandbox | 4.0 | 10.0 | 17.0 | 5.0 | 15.0 |
ไวยากรณ์
<iframe sandbox="value">
ค่าแอตทริบิวต์
Value | Description |
---|---|
(no value) | Applies all restrictions |
allow-forms | Allows form submission |
allow-modals | Allows to open modal windows |
allow-orientation-lock | Allows to lock the screen orientation |
allow-pointer-lock | Allows to use the Pointer Lock API |
allow-popups | Allows popups |
allow-popups-to-escape-sandbox | Allows popups to open new windows without inheriting the sandboxing |
allow-presentation | Allows to start a presentation session |
allow-same-origin | Allows the iframe content to be treated as being from the same origin |
allow-scripts | Allows to run scripts |
allow-top-navigation | Allows the iframe content to navigate its top-level browsing context |
allow-top-navigation-by-user-activation | Allows the iframe content to navigate its top-level browsing context, but only if initiated by user |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
แซนด์บ็อกซ์ <iframe> อนุญาตให้ส่งแบบฟอร์ม:
<iframe src="demo_iframe_sandbox_form.htm" sandbox="allow-forms"></iframe>
ตัวอย่าง
<iframe> แซนด์บ็อกซ์ที่อนุญาตให้ใช้สคริปต์:
<iframe src="demo_iframe_sandbox_origin.htm" sandbox="allow-scripts"></iframe>
❮ แท็ก HTML <iframe>