Obtaining YouTube video ID in a URL and inputting selected video ID into a URL
Posted
by Dave
on Stack Overflow
See other posts from Stack Overflow
or by Dave
Published on 2009-12-29T06:15:27Z
Indexed on
2010/05/20
3:10 UTC
Read the original article
Hit count: 325
I've been having trouble in trying to figure this out. What I am trying to do is, obtain the ID of a video from YouTube, and input the 11 character ID into the css of a div of a specific id by using jquery. I know the URL for the thumbnail of any video, but I just need to be able to change the ID to display different video thumbnails.
<script>
$(document).ready(function() {
function(data){
videoID = data.split('www.youtube.com/v/')[1].split('&')[0];
$("#304817679").append(videoID);
});
$("#304817679").replaceWith("<div id=\"304817679\" style=\"background: url(http://img.youtube.com/vi/"+ $.function(data) +"/0.jpg) no-repeat middle; width: 15px; height: 150px;\"></div>");
});
});
</script>
<div id="304817679">
<div style="display: none;"><object width="248" height="222"><param name="movie" value="http://www.youtube.com/v/vy90n2nNRKQ&rel=0&egm=0&showinfo=0&fs=1"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/vy90n2nNRKQ&rel=0&egm=0&showinfo=0&fs=1" type="application/x-shockwave-flash" width="248" height="222" allowFullScreen="true" wmode="transparent"></embed></object></div>
</div>
Trying to explain this better, I want the 11 Character YouTube Video ID from the embedded code, and put it into the URL of the thumbnail (http://img.youtube.com/vi/"+ function(data) +"/0.jpg). Which, would then also replace the original div (div id="304817679").
Am I on the right track with my script? I'm entirely new to this, and I would appreciate some of the help that's offered here.
© Stack Overflow or respective owner