Atrybut piaskownicy <iframe> HTML

❮ Tag HTML <iframe>

Przykład

<iframe> z dodatkowymi ograniczeniami:

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

Więcej przykładów „Wypróbuj sam” poniżej.


Definicja i użycie

sandboxAtrybut włącza dodatkowy zestaw ograniczeń dla treści w elemencie iframe .

Gdy sandboxatrybut jest obecny, to:

  • traktować treści jako pochodzące z unikalnego źródła
  • zablokuj przesyłanie formularza
  • blokowanie wykonywania skryptu
  • wyłącz interfejsy API
  • uniemożliwić linkom kierowanie na inne konteksty przeglądania
  • uniemożliwić treściom korzystanie z wtyczek (poprzez <embed>, <object>, <applet>lub inne)
  • uniemożliwić treści nawigację w kontekście przeglądania najwyższego poziomu
  • blokować automatycznie uruchamiane funkcje (takie jak automatyczne odtwarzanie wideo lub automatyczne ustawianie kontrolki formularza)

Wartość sandboxatrybutu może być albo pusta (wówczas stosowane są wszystkie ograniczenia), albo lista predefiniowanych wartości oddzielonych spacjami, które usuną określone ograniczenia.


Obsługa przeglądarki

Liczby w tabeli określają pierwszą wersję przeglądarki, która w pełni obsługuje ten atrybut.

Attribute
sandbox 4.0 10.0 17.0 5.0 15.0


Składnia

<iframe sandbox="value">

Wartości atrybutów

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

Więcej przykładów

Przykład

Sandbox <iframe> umożliwiający przesyłanie formularzy:

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

Przykład

Sandbox <iframe> umożliwiający skrypty:

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

❮ Tag HTML <iframe>