Categories
Code Snippet

Snippet – Create YouTube Embedded Frame [JS]

Just share a small Javascript function to help you make a iframe embedded for your content. There exists a regular express to verify the link content Here’s right away: function youtubeEmbeddedFrame (content){ var matches = /(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g.exec(content); if(!matches){ return null; } var iframe = jQuery('<iframe width="300" height="200" frameborder="0" allowfullscreen />'); iframe.attr('src', location.protocol + '//www.youtube.com/embed/' + matches[1]);…