Trying to change/modify the source of any/all iframe on the page where the src includes youtube.com, and get the video id from the src url.
Here’s what I have so far that’s not working.
$(document).ready(function(){
changeYoutube();
function changeYoutube()
{
$('iframe').each(function() {
var that = $(this);
var href = that.attr('src');
if(href.search('youtube.com') != -1) {
that.attr('href', href+'&autoplay=1');
}
});
});
I also need to put the video id from the url into a var. Example url:
http://www.youtube.com/embed/hP9rBDYYFvw?fs=1&feature=oembed
Where “hP9rBDYYFvw” is the video id in that url.
Thanks
This is the solution:
First You have set the href attribute but you must set src attribute of iframe. Second You must first define the function that You call after document ready, and in Your code you haven’t close the function. Best Regards.