网站youtube嵌入的视频不断播放 [英] Website youtube embedded video keeps playing

查看:496
本文介绍了网站youtube嵌入的视频不断播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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



所以我的html代码看起来像这样

 < div id =blanketstyle = 显示:无; >< / DIV> 
< div id =popUpDivstyle =display:none;>
< font size =4color =#ffffff>< a style =color:#ffffffhref =javascript:void(null)onclick =popup('popUpDiv') >关闭< / A><峰; br>< /字体>
< iframe width =560height =315src =http://www.youtube.com/embed/h3Pb6IyFvfgframeborder =0allowfullscreen>< / iframe>
< / div>
< a href =javascript:void(null)onclick =popup('popUpDiv')class =more_details>更多详情< / a>

然而,如果我将浏览器切换到Internet Explorer或Chrome浏览器,当我选择关闭关闭弹出窗口的视频不断播放?我做了一些Google搜索,发现了一些与我的问题相同的问题,但是我只能找到没有按预期工作的代码。

基本上我想在弹出窗口关闭时停止视频,这怎么可能完成。感谢您的帮助

解决方案

之前我面临同样的问题。
我所做的是<当我在jQuery中打开它时关闭弹出窗口并将放回到上时,移除iframe的src 。这样,我确信当弹出窗口关闭时,视频不会继续播放。


编辑添加了一个例子:
/>
在包含视频网址的功能中添加一个可选参数 $ b

 < a href =javascript:void(null)onclick =popup('popUpDiv','http://www.youtube.com/embed/NWHfY_lvKIQ')class =more_details>更多详情< / a> 

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

 函数popup(pPopup,pYt){// pYt可选
$('iframe')。attr('src ',pYt);
}

当您要删除源代码时,在代码中添加此行

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


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

解决方案

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', '');

这篇关于网站youtube嵌入的视频不断播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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