Embed Youtube Video From Url
Im new in all this amazing thing called front end and i´m already working in a project but i need a little help with this: So the thing is that the user could enter a youtube URL
Solution 1:
if you have youtube url https://www.youtube.com/watch?v=sGbxmsDFVnE, you can embed it by taking the video id off the end and putting at the end of youtube.com/embed/
you can get the video id using string.split()
var url = "https://www.youtube.com/watch?v=sGbxmsDFVnE";
var id = url.split("?v=")[1]; //sGbxmsDFVnEvar embedlink = "http://www.youtube.com/embed/" + id; //www.youtube.com/embed/sGbxmsDFVnE
then just make that embed link the source to an existing iframe on the page
document.getElementById("myIframe").src = embedLink;
example of an iframe
<iframe id="myIframe" width="560" height="315" frameborder="0" allowfullscreen></iframe>
Post a Comment for "Embed Youtube Video From Url"