我有一个 YouTube 播放器,它使用 YouTube API 播放视频,问题是它会重定向到另一个页面,然后开始播放视频。
如何让播放器在点击图像时在同一页面弹出,然后开始播放视频?
<a href="play/"><img src="image" alt="button-img" /></a>
//play is the route where YouTube player component is present.
最佳答案
您可以创建一个点击事件并将youtube视频的iframe插入到您想要的位置。这里有一个例子...
HTML:
<a href="#" id="showvideo">Show Video</a>
<div id="test"></div>
JQUERY:
$('a#showvideo').click(function(e) {
e.preventDefault();
$('div#test').html('<iframe id="video" width="420" height="315" src="//www.youtube.com/embed/aS3DPglji0o?rel=0" frameborder="0" allowfullscreen></iframe>');
});
关于javascript - 如何让 Youtube 播放器弹出并播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46860345/