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 +
'&wmode=transparent" frameborder="0" />'
$link.replaceWith(iframe)
})
}
Written by Cedric Ruiz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#