play iframe video on click a link javascript(点击链接 javascript 播放 iframe 视频)
问题描述
我在我的网页中使用了 iframe 视频
.这是我的html代码
I have used a iframe video
in my web page. This is my html code
<iframe id="video1" width="520" height="360" src="aHR0cDovL3d3dy55b3V0dWJlLmNvbS9lbWJlZC9USjJYNGRGaEFDMD9lbmFibGVqc2FwaQ==" frameborder="0" allowtransparency="true" allowfullscreen></iframe>
<a href="#" id="playvideo">Play video</a>
我需要 play
视频 onclick
播放视频链接.我该怎么做?
I need to play
video onclick
the play video link. How can i do that?
推荐答案
这可行,它将 autoplay=1
附加到 url 导致视频开始播放.
This works, it appends autoplay=1
to the url causing the video to start playing.
附录:如果您的视频源还没有查询字符串,那么最好添加 ?
而不是 &
, 有时是这样.这可以通过寻找它的存在来完成.
addendum: If your video's source does not already have a querystring then it would be prudent to add a ?
instead of a &
, as is sometimes the case. This can be done by looking for its existence.
<iframe id="video1" width="520" height="360" src="aHR0cDovL3d3dy55b3V0dWJlLmNvbS9lbWJlZC9USjJYNGRGaEFDMD9lbmFibGVqc2FwaQ==" frameborder="0" allowtransparency="true" allowfullscreen></iframe>
<a href="#" id="playvideo">Play video</a>
<script>
//use .one to ensure this only happens once
$("#playvideo").one(function(){
//as noted in addendum, check for querystring exitence
var symbol = $("#video1")[0].src.indexOf("?") > -1 ? "&" : "?";
//modify source to autoplay and start video
$("#video1")[0].src += symbol + "autoplay=1";
});
</script>
但是,大多数人天生就明白,如果他们想要播放视频,他们只需点击它,我建议将其留给他们或通过自动播放开始视频.
However, most people inherently understand that if they want a video to play, they will just click on it and I would suggest just leaving that to them or starting the video off with autoplay.
还需要提到自动播放在移动设备(由 Android 或 iOS 驱动)上不起作用
Also need to mention that autoplay does not work on mobile devices (powered by Android or iOS)
这篇关于点击链接 javascript 播放 iframe 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:点击链接 javascript 播放 iframe 视频
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01