导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML 参考手册

HTML 元素(功能排序) HTML 浏览器支持 HTML 属性 HTML 全局属性 HTML 事件 HTML 颜色 HTML 画布 HTML 音频/视频 HTML 字符集 HTML 文档类型 HTML URL 编码 HTML 语言代码 HTML 国家代码 HTTP 状态消息 HTTP 请求方法 PX-EM 转换 键盘快捷键

HTML 标签

<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <iframe> sandbox 属性


实例

带有额外限制的<iframe>:

<iframe src="demo_iframe_sandbox.htm" sandbox></iframe>
亲自试一试 »

下面有更多实例。


定义和用法

sandbox 属性为 iframe 中的内容启用了一组额外的限制。

当 sandbox 沙盒属性存在时,它将:

  • 将内容视为来自唯一来源
  • 集体提交表格
  • 阻止脚本执行
  • 禁用API
  • 防止链接指向其他浏览上下文
  • 阻止内容使用插件 (通过<embed>,<object>,<applet>, 或其他方式)
  • 阻止内容浏览其顶级浏览上下文
  • 阻止自动触发功能(例如自动播放视频或自动对焦窗体控件)

sandbox 属性的值既可以是 sandbox(然后应用所有限制),也可以是将删除特定限制的预定义值的空格分隔列表。


浏览器支持

表中的数字表示支持该属性的第一个浏览器版本。

属性          
sandbox 4.0 10.0 17.0 5.0 15.0

语法

<iframe sandbox="value">

属性值

描述
(no value) 应用所有限制
allow-forms 允许表单提交
allow-modals 允许打开模式窗口
allow-orientation-lock 允许锁定屏幕方向
allow-pointer-lock 允许使用指针锁API
allow-popups 允许弹出窗口
allow-popups-to-escape-sandbox 允许弹出窗口在不继承沙盒的情况下打开新窗口
allow-presentation 允许启动演示会话
allow-same-origin 允许将iframe内容视为来自同一来源
allow-scripts 允许运行脚本
allow-top-navigation 允许iframe内容浏览其顶级浏览上下文
allow-top-navigation-by-user-activation 允许iframe内容在其顶级浏览上下文中导航,但前提是由用户启动

更多实例

实例

允许表单提交的<iframe> 沙盒:

<iframe src="demo_iframe_sandbox_form.htm" sandbox="allow-forms"></iframe>
亲自试一试 »
 

实例

允许脚本的<iframe> 沙盒:

<iframe src="demo_iframe_sandbox_origin.htm" sandbox="allow-scripts"></iframe>
亲自试一试 »

Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。