定義
如果被規定為空字符串(sandbox=""),sandbox 屬性將會啟用一系列對行內框架中內容的額外限制。
sandbox 屬性的值既可以是一個空字符串(應用所有的限制),也可以是空格分隔的預定義值列表(將移除特定的限制)。
用法
1. sandbox=""
應用所有限制
2. sandbox="allow-same-origin"
允許 iframe 內容被視為與包含文檔有相同的來源。
3. sandbox="allow-top-navigation"
允許 iframe 內容從包含文檔導航(加載)內容。
可用於禁用外部網站的JS跳轉、target="_parent"、target="_top"等
4. sandbox="allow-forms"
允許表單提交。
5. sandbox="allow-scripts"
允許腳本執行,即允許iframe運行腳本(但不創建彈出窗口)。
可用於禁用外部網站的JS
6. sandbox="allow-popups"
允許彈出窗口(如window.open,target="_blank")。
5. sandbox="allow-scripts"
允許彈出窗口逃離沙箱:允許一個沙箱文件打開新窗口不強制使用沙盒。
實例
例如:此iframe只允許加載script,其他的全部限制。
<iframe width="930" height="630" sandbox="allow-scripts" src="http://www.baidu.com"></iframe>
遇到的問題:
iframe使用sandbox屬性后,即使將所有值設為允許,頁面中的flash也無法使用
參考:
HTML <iframe> 標簽的 sandbox 屬性
