Converting youtube video link to embed link with JavaScript

by Max Rohde,

Videos on youtube usually have a URI such as the following:

These URIs cannot be used to embed the video in an iframe such as the following:

In order to work as part of an embedded iframe, youtube video links must be in the following format:

Luckily, given any 'normal' youtube link, it is very easy to generate such an embed link. In JavaScript, this can be done with the following function:

function createYouTubeEmbedLink (link) {
 return link.replace("", "");
Categories: javascript