HTML中的YouTube视频无法使用 [英] YouTube video in HTML not working
问题描述
我尝试从数据库获取YouTube视频的网址并将其嵌入到网页中。
我收到发生错误,请稍后再试讯息。
请帮忙! :(b / b)
数据库中的字符串: https ://www.youtube.com/watch?v = JjFsNSoDZK8
HTML代码(在表格内):
< tr>< td colspan = 3>< iframe id ='Trailer'width =640height =360src =frameborder = 0allowfullscreen>< / iframe>< / td>< / tr>
JS代码(jQuery):
$(#MovieDetails)。find(#Trailer)。attr('src' ,arr ['Trailer']。replace(youtube.com /,youtube.com/embed/)+?feature = player_detailpage);
$ b $(这里,MovieDetails是表的id); 另外,那个字符串在最后:?feature = player_detailpage,即使没有它也不是工作。
尝试了多种方法来更改URL字符串,但似乎无法找到正确的。 b
编辑:如果我使用YouTube上的代码(它可以让你看电影信息 - >分享 - >嵌入)并将其硬编码到我的页面,它工作。
> arr ['Trailer'] ==https://www.youtube.com/watch?v=JjFsNSoDZK8尝试更换你的替换为:
arr ['Trailer']。replace(https://www.youtube.com / watch?v =,//www.youtube.com/embed/);
jsFiddle - http://jsfiddle.net/WFd79/
I try to get a URL of a YouTube-video from database and embed it in a page.
I get the "An error occured. Please try again later" message. Pls help! :(
String in the DB: https://www.youtube.com/watch?v=JjFsNSoDZK8
HTML code (inside a table):
<tr><td colspan=3><iframe id='Trailer' width="640" height="360" src="" frameborder="0" allowfullscreen></iframe></td></tr>
JS code (jQuery):
$("#MovieDetails").find("#Trailer").attr('src',arr['Trailer'].replace("youtube.com/","youtube.com/embed/") + "?feature=player_detailpage");
(Here, MovieDetails is the id of the table); Also, that string at the end: "?feature=player_detailpage", even without it is not working.
Tried several ways to change the URL-string but cannot seem to find the right one. Same mistake always.
EDIT: If I use the code from YouTube (that it gives you in movie info -> share -> embed) and hardcode it in my page, it works.
Assuming that arr['Trailer'] == "https://www.youtube.com/watch?v=JjFsNSoDZK8"
Try to change your replace to the following:
arr['Trailer'].replace("https://www.youtube.com/watch?v=", "//www.youtube.com/embed/");
jsFiddle - http://jsfiddle.net/WFd79/
这篇关于HTML中的YouTube视频无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!