Atribut kotak pasir <iframe> HTML

tag HTML <iframe>

Contoh

Sebuah <iframe> dengan batasan tambahan:

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

Lebih banyak contoh "Coba Sendiri" di bawah ini.


Definisi dan Penggunaan

Atribut sandboxmengaktifkan serangkaian batasan tambahan untuk konten di iframe.

Ketika sandboxatribut hadir, dan itu akan:

  • perlakukan konten sebagai berasal dari asal yang unik
  • pengiriman formulir blokir
  • blokir eksekusi skrip
  • nonaktifkan API
  • mencegah tautan menargetkan konteks penjelajahan lainnya
  • mencegah konten menggunakan plugin (melalui <embed>, <object>, <applet>, atau lainnya)
  • mencegah konten untuk menavigasi konteks penelusuran tingkat atas
  • memblokir fitur yang dipicu secara otomatis (seperti memutar video secara otomatis atau memfokuskan kontrol formulir secara otomatis)

Nilai sandboxatribut bisa kosong (kemudian semua batasan diterapkan), atau daftar nilai yang telah ditentukan sebelumnya yang dipisahkan oleh spasi yang akan MENGHAPUS batasan tertentu.


Dukungan Peramban

Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung atribut tersebut.

Attribute
sandbox 4.0 10.0 17.0 5.0 15.0


Sintaksis

<iframe sandbox="value">

Nilai Atribut

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

Lebih Banyak Contoh

Contoh

Kotak pasir <iframe> memungkinkan pengiriman formulir:

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

Contoh

Kotak pasir <iframe> memungkinkan skrip:

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

tag HTML <iframe>