【发布时间】:2014-02-13 22:14:39
【问题描述】:
当我将视频 URL 粘贴到博客文章中时,我希望它使用 YouTube API 显示为具有自定义参数的 iframe 嵌入式播放器。当我嵌入视频时,我不想每次都手动添加参数。这是我的 JS:
$('body').html(function(i, html) {
return html.replace(/(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, '<center><iframe width="640" height="360" src="http://www.youtube.com/embed/$1?modestbranding=1&rel=0&wmode=transparent&theme=light&color=white" frameborder="0" allowfullscreen></iframe></center>').replace(/(?:http:\/\/)?(?:www\.)?(?:vimeo\.com)\/(.+)/g, '<center><iframe src="//player.vimeo.com/video/$1" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></center>').replace(/(?:http:\/\/)?(?:dailymotion\.com|dai\.ly)\/(.+)/g, '<center><iframe frameborder="0" width="560" height="315" src="http://www.dailymotion.com/embed/video/$1?logo=0&foreground=ffffff&highlight=1bb4c6&background=000000" allowfullscreen></iframe></center>');
});
但是当我将它转移到我在 Blogger 上的网站时,它不起作用 (example)。
谁能帮帮我?
【问题讨论】:
-
我想这样做,以便可以将参数添加到嵌入 URL。我知道如何嵌入视频,但我不想每次都手动添加参数。
-
为什么它在您的网站上不起作用?你有任何错误吗?查看链接,我可以看到一篇嵌入 YouTube 视频的文章
-
当您点击“播放”时出现错误,当您点击右下角的“YouTube”图标时,它会将您带到www.youtube.com/?
标签: javascript jquery html iframe youtube