网站 YouTube 嵌入视频不断播放

发布于 2024-12-07 21:23:58 字数 1046 浏览 0 评论 0原文

我正在使用 youtube 提供的 iframe 在我的网站上嵌入视频。

我还使用了一个 css 弹出窗口,这是我从这个页面学到的 http://www.pat-burt.com/web-development/how-to-do-a-css-popup-without-opening-a-new-window/

所以我的html代码看起来像

<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<font size="4" color="#ffffff"><a style="color: #ffffff" href="javascript:void(null)" onclick="popup('popUpDiv')">Close</a><br></font>
<iframe width="560" height="315" src="http://www.youtube.com/embed/h3Pb6IyFvfg" frameborder="0" allowfullscreen></iframe>
</div>
<a href="javascript:void(null)" onclick="popup('popUpDiv')" class="more_details">more details</a>

这样一切都按我想要的方式工作,但是如果我切换当我选择关闭来关闭弹出窗口时,我的浏览器连接到 Internet Explorer 或 Chrome 时视频会继续播放吗?我做了一些谷歌搜索,发现其他人也有同样的问题,但是我只能找到无法按预期工作的代码。

基本上我想在弹出窗口关闭时停止视频,如何做到这一点。感谢您的帮助

I'm using the iframe youtube gave me to embed a video on my website.

I also am using a css popup which i learned from this page
http://www.pat-burt.com/web-development/how-to-do-a-css-popup-without-opening-a-new-window/

So my html code looks like this

<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<font size="4" color="#ffffff"><a style="color: #ffffff" href="javascript:void(null)" onclick="popup('popUpDiv')">Close</a><br></font>
<iframe width="560" height="315" src="http://www.youtube.com/embed/h3Pb6IyFvfg" frameborder="0" allowfullscreen></iframe>
</div>
<a href="javascript:void(null)" onclick="popup('popUpDiv')" class="more_details">more details</a>

And everything is working as i want it to however if I switch my browser to either internet explorer or chrome when i select close to close the popup the video keeps playing? I've done some googling and found others with my same issue however I only could find code that didn't work as it was supposed to.

Basically I'd like to stop the video when the popup is closed how could this be done. Thank you for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

死开点丶别碍眼 2024-12-14 21:23:58

我之前也遇到过同样的问题。
我所做的是当我关闭弹出窗口时删除 iframe 的 src 并在 jQuery 中打开它时将其重新打开。这样,我确信当弹出窗口关闭时视频不会继续播放。

编辑添加示例:

在包含视频网址的函数中添加可选参数

<a href="javascript:void(null)" onclick="popup('popUpDiv', 'http://www.youtube.com/embed/NWHfY_lvKIQ')" class="more_details">more details</a>

使用视频网址在函数中设置 iframe 的 src

function popup(pPopup, pYt){ //pYt optional
    $('iframe').attr('src', pYt);
}

根据需要在代码中添加此行删除源

$('iframe').attr('src', '');

I faced the same problem before.
What I did is remove the src of the iframe when I close the popup and put it back on when I open it in jQuery. This way, i'm sure the video won't keep playing when the popup is closed.

Edit Added an Exemple:

Add an optional parameter in your function containing the video url

<a href="javascript:void(null)" onclick="popup('popUpDiv', 'http://www.youtube.com/embed/NWHfY_lvKIQ')" class="more_details">more details</a>

Set the src of your iframe in your function with the video url

function popup(pPopup, pYt){ //pYt optional
    $('iframe').attr('src', pYt);
}

Add this line in your code when you want to remove the source

$('iframe').attr('src', '');
一影成城 2024-12-14 21:23:58

您还可以放弃 iframe 代码并使用 YouTube 嵌入。然后,在您的 javascript 事件中,您可以 player.pauseVideo(); 其中,player 是您的嵌入对象。

使用 Youtube 播放器 API:http://code.google.com/apis/youtube /js_api_reference.html#Playback_controls

You can also ditch the iframe code and use a youtube embed. Then in your javascript event you can player.pauseVideo(); where player is your embedded object.

Use the Youtube Player API: http://code.google.com/apis/youtube/js_api_reference.html#Playback_controls

浅暮の光 2024-12-14 21:23:58

更改帧的显示不会停止视频。当弹出窗口关闭时,您必须删除 iframe 元素。

Changing the display of the frame isn't going to stop the video. You would have to remove the iframe element when the popup closes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文