Disabling 'allowfullscreen' from the youtube in the javascript

2.3k Views Asked by At

To prevent double click fullscreen from the iframe all you do is remove 'allowfullscreen' from the iframe code.

<iframe width="606" height="344" src="https://www.youtube.com/embed/M7lc1UVf-VE" frameborder="0" /*allowfullscreen*/></iframe>

But how would it be done through the youtube javascript api if you’re not using the iframe?

I can’t seem to figure it out

This seems like it would be simple to do but I can't seem to figure it out.

How would this be done?

I've been looking all over and haven't found any code that does this.

Nothing I'm trying seems to be working at all.

If it's able to be done via the iframe, shouldn't it be able to be done through the javascript also?

Also: fs: 0; Doesn't remove Double click fullscreen.

https://jsfiddle.net/zb6mkug3/829/

<div class="player"></div>

    (function iife() {
    "use strict";
    const tag = document.createElement("script");
    tag.src = "https://www.youtube.com/player_api";
    const firstScriptTag = document.getElementsByTagName("script")[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    function onPlayerReady(event) {
        const youtubePlayer = event.target;
        youtubePlayer.setVolume(0); // percent
    }
    window.onYouTubePlayerAPIReady = function() {
        new YT.Player(document.querySelector(".player"), {
            height: '315',
            width: '560',
            host: 'https://www.youtube-nocookie.com',
            videoId: 'M7lc1UVf-VE',
            playerVars: {
                controls: 1,
                fs: 0,
            },
            events: {
                "onReady": onPlayerReady
            }
        });
    };
}());
1

There are 1 best solutions below

7
On

In playerVars, simply add fs: 0, that will disable the fullscreen choice:

playerVars: {
    controls: 1,
    fs: 0
},

source