Atributo de sandbox HTML <iframe>

❮ Etiqueta HTML <iframe>

Ejemplo

Un <iframe> con restricciones adicionales:

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

Más ejemplos de "Pruébelo usted mismo" a continuación.


Definición y uso

El sandboxatributo habilita un conjunto adicional de restricciones para el contenido del iframe.

Cuando el sandboxatributo está presente, y lo hará:

  • tratar el contenido como si tuviera un origen único
  • bloqueo de envío de formulario
  • bloquear la ejecución del script
  • deshabilitar las API
  • evitar que los enlaces apunten a otros contextos de navegación
  • evitar que el contenido use complementos (a través <embed>de <object>, <applet>u otros)
  • evitar que el contenido navegue por su contexto de navegación de nivel superior
  • bloquear funciones activadas automáticamente (como reproducir automáticamente un video o enfocar automáticamente un control de formulario)

El valor del sandboxatributo puede estar vacío (entonces se aplican todas las restricciones) o una lista separada por espacios de valores predefinidos que ELIMINARÁN las restricciones particulares.


Compatibilidad con navegador

Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con el atributo.

Attribute
sandbox 4.0 10.0 17.0 5.0 15.0


Sintaxis

<iframe sandbox="value">

Valores de atributo

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

Más ejemplos

Ejemplo

Un sandbox <iframe> que permite el envío de formularios:

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

Ejemplo

Un sandbox <iframe> que permite scripts:

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

❮ Etiqueta HTML <iframe>