Thuộc tính hộp cát HTML <iframe>

❮ Thẻ HTML <iframe>

Thí dụ

Một <iframe> với các hạn chế bổ sung:

<iframe src="demo_iframe_sandbox.htm" sandbox></iframe>

Thêm các ví dụ "Hãy tự mình thử" bên dưới.


Định nghĩa và Cách sử dụng

Thuộc sandboxtính này cho phép thêm một số hạn chế đối với nội dung trong iframe.

Khi sandboxthuộc tính hiện diện và nó sẽ:

  • coi nội dung là từ một nguồn gốc duy nhất
  • gửi biểu mẫu khối
  • thực thi tập lệnh khối
  • vô hiệu hóa các API
  • ngăn chặn các liên kết nhắm mục tiêu đến các bối cảnh duyệt web khác
  • ngăn nội dung sử dụng các plugin (thông qua <embed>, hoặc khác <object>) <applet>
  • ngăn nội dung điều hướng ngữ cảnh duyệt cấp cao nhất của nó
  • chặn các tính năng được kích hoạt tự động (chẳng hạn như tự động phát video hoặc tự động lấy nét điều khiển biểu mẫu)

Giá trị của sandboxthuộc tính có thể để trống (sau đó tất cả các hạn chế được áp dụng) hoặc danh sách các giá trị được xác định trước được phân tách bằng dấu cách sẽ LOẠI BỎ các hạn chế cụ thể.


Hỗ trợ trình duyệt

Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ thuộc tính.

Attribute
sandbox 4.0 10.0 17.0 5.0 15.0


Cú pháp

<iframe sandbox="value">

Giá trị thuộc tính

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

Các ví dụ khác

Thí dụ

Hộp cát <iframe> cho phép gửi biểu mẫu:

<iframe src="demo_iframe_sandbox_form.htm" sandbox="allow-forms"></iframe>

Thí dụ

Hộp cát <iframe> cho phép các tập lệnh:

<iframe src="demo_iframe_sandbox_origin.htm" sandbox="allow-scripts"></iframe>

❮ Thẻ HTML <iframe>