HTML <iframe>サンドボックス属性

❮HTML<iframe>タグ

追加の制限がある<iframe>:

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

以下の「自分で試してみてください」の例をもっと見てください。


定義と使用法

このsandbox属性により、iframe内のコンテンツに対する追加の制限セットが有効になります。

sandbox属性が存在する場合、次のようになります。

  • コンテンツを固有の起源のものとして扱います
  • フォーム送信をブロックする
  • スクリプトの実行をブロックする
  • APIを無効にする
  • リンクが他のブラウジングコンテキストをターゲットにしないようにする
  • コンテンツがプラグインを使用できないようにする(、、、、またはその他を介し <embed>て)<object> <applet>
  • コンテンツがトップレベルのブラウジングコンテキストをナビゲートするのを防ぎます
  • 自動的にトリガーされる機能をブロックする(ビデオの自動再生やフォームコントロールの自動フォーカスなど)

属性の値は、sandbox空(すべての制限が適用される)、または特定の制限を削除する事前定義された値のスペースで区切られたリストのいずれかです。


ブラウザのサポート

表の数字は、属性を完全にサポートする最初のブラウザーバージョンを示しています。

Attribute
sandbox 4.0 10.0 17.0 5.0 15.0


構文

<iframe sandbox="value">

属性値

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

その他の例

フォーム送信を可能にする<iframe>サンドボックス:

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

スクリプトを許可する<iframe>サンドボックス:

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

❮HTML<iframe>タグ