Last Updated: February 25, 2016
·
2.321K
· elclanrs

Embed Youtube video from link with custom params

$.fn.linkToYoutube = function(ops) {

  var o = $.extend({
    width: 480,
    height: 320,
    params: ''
  }, ops)

  return this.each(function () { 
    var $link = $(this),
        href = $link.attr('href'),
        id = /\?v\=(\w+)/.exec(href)[1],
        iframe = '<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" />'
    $link.replaceWith(iframe) 
  })

}

Demo: http://jsfiddle.net/elclanrs/6ZS3w/