网站 YouTube 嵌入视频不断播放
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我之前也遇到过同样的问题。
我所做的是当我关闭弹出窗口时删除 iframe 的 src 并在 jQuery 中打开它时将其重新打开。这样,我确信当弹出窗口关闭时视频不会继续播放。
编辑添加示例:
在包含视频网址的函数中添加可选参数
使用视频网址在函数中设置 iframe 的 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
Set the src of your iframe in your function with the video url
Add this line in your code when you want to remove the source
您还可以放弃 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
更改帧的显示不会停止视频。当弹出窗口关闭时,您必须删除 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.