Junaid Khan
Junaid Khan

Reputation: 45

How to run a user entered youtube url link on your webpage without embedding

I am making a website where users can provide a link to their YouTube videos while filling up a form.

How can these videos be played in an iframe or a video tag on the website without being embedded?

I have tried the following but the video is not playing inside the webpage

<iframe src='".$link."'></iframe>

//where $link = "https://www.youtube.com/watch?v=KUh2O8HylUM";
//or $link = "//www.youtube.com/watch?v=KUh2O8HylUM";

Upvotes: 0

Views: 102

Answers (1)

Yosef Tukachinsky
Yosef Tukachinsky

Reputation: 5895

<div id="youtube_container"></div>

<script>
    var link = prompt("enter youtube link");
    link = link.split("v=")[1];
    $("#youtube_container").html("<iframe width='854' height='480' src='https://www.youtube.com/embed/" + link + "' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>");
</script>

Upvotes: 1

Related Questions