【问题标题】:Embed videos with iframe in React JSX在 React JSX 中使用 iframe 嵌入视频
【发布时间】:2016-08-17 11:25:05
【问题描述】:

为幼稚的问题道歉,因为显然我遗漏了一些明显的东西。

我的简单无状态 iframe 组件:

const Video = ({ src }) => (
  <iframe
    allowFullScreen
    frameborder="0"
    height="315"
    src={src}
    width="560"
  />
);
export default Video;

我在 Parent 无状态组件中这样使用:

import Video from 'Video';

const Parent = (props) => (
  <div>
    <Video src="https://www.youtube.com/watch?v=WlRxNSRA7Rg"/>
  </div>
);

export default Parent;

这似乎可以正确渲染,但 iframe 是空白的。

我怀疑这与 React 支持的媒体事件有关,但我们将不胜感激。

【问题讨论】:

    标签: javascript iframe reactjs


    【解决方案1】:

    由于 XSS 攻击,以这种方式设置 iframe 的 src 被认为是危险的。您将不得不使用危险的SetInnerHTML。阅读它here

    看看this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      • 2016-10-09
      • 2012-10-22
      相关资源
      最近更新 更多