【问题标题】:Can I set the "src" of an iFrame?我可以设置 iFrame 的“src”吗?
【发布时间】:2016-05-23 15:16:03
【问题描述】:

我有一个使用 iFrame 嵌入 Youtube 视频的 HTML 文件。但是在视频开始加载之前,我需要传递一个 URL,因为 iFrame 只是充当容器。

是否可以使用 Javascript 来实现?

【问题讨论】:

  • 是的,设置src属性。
  • 就这样?,但是我如何告诉 JavaScript 仅在我设置属性时才加载视频,而不是一开始就加载?。
  • 检查this 示例。

标签: javascript html iframe


【解决方案1】:

如果它符合您的要求,请检查此示例

<iframe id="custom-frame" src="/test.html"></iframe>
<p>Click the button to change the value of the src attribute in the iframe </p>
<button onclick="changeFrame()">Try it</button>
<script>
      function changeFrame() {
        document.getElementById("custom-frame").src = "http://www.facebook.com";
      }
</script>

【讨论】:

  • 好的。因此,如果我最初没有为 iFrame 设置“src”,这意味着在我自己设置正确之前它什么都不做?。
  • 是的,它不会做任何事情。
猜你喜欢
  • 1970-01-01
  • 2012-04-04
  • 2014-04-11
  • 2011-07-06
  • 1970-01-01
  • 1970-01-01
  • 2014-03-27
  • 2017-04-12
  • 1970-01-01
相关资源
最近更新 更多