I'm using the iframe youtube gave me to embed a video on my website.
我用youtube上的iframe在我的网站上嵌入一个视频。
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/
我还在使用一个css弹出窗口,这是我从这个页面http://www.pat-burt.com/web-development/how-to- a-css-pop - out-open -a-new-window/中学到的
So my html code looks like this
我的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>
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.
一切都如我所愿但如果我将浏览器切换到ie或chrome当我选择关闭弹出窗口时视频会继续播放?我用谷歌搜索了一下,找到了一些有同样问题的代码,但是我只能找到一些不能正常工作的代码。
Basically I'd like to stop the video when the popup is closed how could this be done. Thank you for any help
基本上,我想在弹出窗口关闭的时候停止这个视频。谢谢你的帮助
3 个解决方案
#1
8
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
我以前也遇到过同样的问题。我所做的就是当我关闭弹出窗口时删除iframe的src,当我用jQuery打开它时重新打开它。这样,当弹出窗口关闭时,我确定视频不会继续播放。编辑添加了一个示例:在函数中添加一个包含视频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
将你的iframe的src设置为视频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', '');
#2
1
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.
您还可以丢弃iframe代码并使用youtube嵌入。然后在javascript事件中,您可以播放。玩家是你的嵌入对象。
Use the Youtube Player API: http://code.google.com/apis/youtube/js_api_reference.html#Playback_controls
使用Youtube Player API: http://code.google.com/apis/youtube/js_api_reference.html#Playback_controls
#3
0
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.
更改帧的显示不会停止视频。当弹出窗口关闭时,您必须删除iframe元素。
#1
8
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
我以前也遇到过同样的问题。我所做的就是当我关闭弹出窗口时删除iframe的src,当我用jQuery打开它时重新打开它。这样,当弹出窗口关闭时,我确定视频不会继续播放。编辑添加了一个示例:在函数中添加一个包含视频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
将你的iframe的src设置为视频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', '');
#2
1
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.
您还可以丢弃iframe代码并使用youtube嵌入。然后在javascript事件中,您可以播放。玩家是你的嵌入对象。
Use the Youtube Player API: http://code.google.com/apis/youtube/js_api_reference.html#Playback_controls
使用Youtube Player API: http://code.google.com/apis/youtube/js_api_reference.html#Playback_controls
#3
0
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.
更改帧的显示不会停止视频。当弹出窗口关闭时,您必须删除iframe元素。