HTML-<iframe> -Sandbox- Attribut

❮ HTML <iframe>-Tag

Beispiel

Ein <iframe> mit zusätzlichen Einschränkungen:

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

Weitere „Probieren Sie es selbst“-Beispiele weiter unten.


Definition und Verwendung

Das sandboxAttribut aktiviert einen zusätzlichen Satz von Einschränkungen für den Inhalt im Iframe.

Wenn das sandboxAttribut vorhanden ist, und es wird:

  • Behandeln Sie den Inhalt als von einem einzigartigen Ursprung stammend
  • Formularübermittlung blockieren
  • Skriptausführung blockieren
  • APIs deaktivieren
  • Verhindern Sie, dass Links auf andere Browserkontexte abzielen
  • verhindern, dass Inhalte Plugins verwenden (durch <embed>, <object>, <applet>, oder andere)
  • verhindern, dass der Inhalt in seinem Browserkontext der obersten Ebene navigiert
  • Blockieren Sie automatisch ausgelöste Funktionen (z. B. das automatische Abspielen eines Videos oder das automatische Fokussieren eines Formularsteuerelements)

Der Wert des sandboxAttributs kann entweder leer sein (dann werden alle Einschränkungen angewendet) oder eine durch Leerzeichen getrennte Liste vordefinierter Werte, die die jeweiligen Einschränkungen AUFHEBEN.


Browser-Unterstützung

Die Zahlen in der Tabelle geben die erste Browserversion an, die das Attribut vollständig unterstützt.

Attribute
sandbox 4.0 10.0 17.0 5.0 15.0


Syntax

<iframe sandbox="value">

Attributwerte

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

Mehr Beispiele

Beispiel

Eine <iframe>-Sandbox, die das Senden von Formularen ermöglicht:

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

Beispiel

Eine <iframe>-Sandbox, die Skripte zulässt:

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

❮ HTML <iframe>-Tag