反应 iframe 沙箱不允许任何东西

kap*_*053 5 html iframe sandbox reactjs

我需要在 React 应用程序中使用 iframe 沙箱。其中,我不想允许任何事情并限制一切。

因此,当我将沙箱作为空白传递时,例如:-

<iframe
  frameBorder="0"
  ref={(container) => { this.container[index] = container; }}
  srcDoc={thread.body}
  sandbox
/>
Run Code Online (Sandbox Code Playgroud)

我得到这个 - “警告:收到true非布尔属性sandbox。”

反应:“^16.5.2”

rze*_*lek 3

React 的处理方式<iframe sandbox />就跟原来一样,<iframe sandbox={true} />但这里是不正确的。

根据此处的文档: https: //www.w3schools.com/tags/att_iframe_sandbox.asp,浏览器期望 sandbox prop 为空值。

你应该简单地使用

<iframe
  frameBorder="0"
  ref={(container) => { this.container[index] = container; }}
  srcDoc={thread.body}
  sandbox=""
/>
Run Code Online (Sandbox Code Playgroud)

编辑:

正如OP在评论中回答的那样,他必须这样做sandbox="allow-same-origin allow-popups"