将 Javascript 用于 iFrame src URL [英] Using Javascript for iFrame src URL

查看:44
本文介绍了将 Javascript 用于 iFrame src URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 YouTube API 和 JavaScript,但无法使其正常工作.我正在尝试使用 JavaScript 将视频 URL 提供给 iFrame.这是我的 HTML 页面正文中的内容:

I'm playing around with the YouTube API and JavaScript and I can't get this to work. I'm trying to use JavaScript to give the video URL to the iFrame. This is what I have in the body of my HTML page:

<iframe id="ytplayer" type="text/html" width="720" height="405" src="" frameborder="0" allowfullscreen>

<script type="text/javascript">
    document.getElementById("ytplayer").src = "https://www.youtube.com/embed/0rhwc5_iWkA?autoplay=1";
</script>

这只是一个简单的例子,但我无法显示视频播放器.我已经研究了各种方法来实现相同的结果,但没有任何效果.怎么了?

It's just a trivial example but I can't get the video player to appear. I've looked at various ways to achieve the same result but nothing works. What's going wrong?

推荐答案

您需要关闭 iframe.

You need to close your iframe.

<!DOCTYPE HTML>
<html>
<body>
    <iframe id="ytplayer" type="text/html" width="720" height="405" src="" frameborder="0" allowfullscreen></iframe>
    <script type="text/javascript">
        document.getElementById("ytplayer").src = "https://www.youtube.com/embed/0rhwc5_iWkA?autoplay=1";
    </script>
</body>
</html>

这篇关于将 Javascript 用于 iFrame src URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆