JavaScript Embedding YouTube videos from links

Posted by midhun pottmmal On Wednesday, 23 January 2013 0 comments

JavaScript Embedding YouTube videos from links

Embedding video to a webpage make a real change in the early day’s web. It  can make a multimedia interaction with web user and author .so feel of that website become more realistic .most of users have broadband connection so they are flexible with video contents .one of the most  common used method  is  using a flash player and flv videos those hosted in an external server ,like YouTube .
Embedding YouTube

Code

 function linkToYoutube(link, ops) {
         var o = $.extend({
         width: 480,
         height: 320,
         params: ''
         }, ops);
  
          var id = /\?v\=(\w+)/.exec(link)[1];

          return '<iframe style="display: block;"'+
         ' class="youtube-video" type="text/html"'+
         ' width="' + o.width + '" height="' + o.height +
         ' "src="http://www.youtube.com/embed/' + id + '?' + o.params +
          '&amp;wmode=transparent" frameborder="0" />';
         }

      $('a').each(function(){
      var link = $(this).attr('href');
     $(this).html( linkToYoutube(link, { params: 'theme=light' }) );
    })

Download & Live Code Edit

0 comments:

Post a Comment

Fashion