Play YouTube Video in IFRAME in HTML
Introduction: Hello Friends!! In this article I will explain about the implementation of playing or embed YouTube Videos by using IFRAME with AutoPlay option in using HTML.
Implementation: The following HTML code will use a HTML TextBox with id named text_url , and a button with id named button_play and a IFRAME with the id named video_play control. Here I will assign a javascript OnClick event handler to the Button .When the button with id named button_play is clicked, first the YouTube Video URL is fetched from the TextBox that is entered by the user and then YouTube Video ID is extracted from the URL.
The extracted YouTube Video ID will be appended in the YouTube embed video URL that will be entered by the user and the URL of the video will be set to the SRC property of the HTML IFRAME control.
To AutoPlay option for the video, an another parameter autoplay=1 will be used to the YouTube embed video URL.
<input type="text" id="text_url" style="width: 300px" />
<input type="button" id="button_play" value="Play" />
<hr />
<iframe id="video_play" width="420" height="315" frameborder="0" style="display: none"
allowfullscreen></iframe>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("body").on("click", "#buttotn_Play", function () {
var url = $("#text_url").val();
url = url.split('v=')[1];
$("#video_play")[0].src = "https://www.youtube.com/embed/" + url + "?autoplay=1";
$("#video_play").show();
});
</script>
Conclusion: In above code, I explained that how to play or embed YouTube Videos by using IFRAME with AutoPlay option in using HTML. This code is very helpful for every developer. Bye Bye everyone and take care of you Developers. We will come back shortly with the new article.
Regards
Using Asp.net
Comments
Post a Comment