How To Add A Button To Play Youtube Video Full Screen Using Javascript?
I'm coding a Google Chrome extension where I embed a YouTube video:
Solution 2:
For the full screen on YouTube iFrame First of all you have to use the YouTube Iframe Api By Adding
<scriptsrc="https://www.youtube.com/iframe_api"></script>
Include iframe as
<iframe id="youtube_videos_url" allowfullscreen="1" class="video-js vjs-default-skin"
src="http://www.youtube.com/embed/8xXrbKJSp6w?wmode=opaque&enablejsapi=1&version=3&autoplay=0&controls=0" frameborder="0">
</iframe>
For Button
<button id="fs"type="button" data-state="go-fullscreen">Fullscreen</button>
Then the code for full-screen the YouTube Video
$(document).ready(function () {
var player = newYT.Player('youtube_videos_url');
$('#fs').on('click', function () {
player.playVideo();
var $$ = document.querySelector.bind(document);
var iframe = $$('#youtube_videos_url');
var req = iframe.requestFullscreen
|| iframe.webkitRequestFullscreen
|| iframe.mozRequestFullScreen
|| iframe.msRequestFullscreen;
req.call(iframe);
});
});
I hope with this function will help you.
Post a Comment for "How To Add A Button To Play Youtube Video Full Screen Using Javascript?"