YouTube Iframe API Embed with No Ads on Video

In my project, I am using YouTube video embeds (not my videos) and I want them to not display ads.

When I use Iframe embed (without Iframe API - with youtube-nocookie.com), it works, ads are not displayed, which I want.

<iframe id="video" src="https://www.youtube-nocookie.com/embed/7TXKBlBBbIA?fs=0&modestbranding=1&playsinline=1&rel=0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" width="640" height="360" frameborder="0"></iframe>

But when I use Iframe API (with youtube-nocookie.com), ads are displayed, which I don’t want.

// HTML
<div id="video"></div>

// JS
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

function onYouTubeIframeAPIReady() {
    video = new YT.Player('video', {
        height: 360,
        width: 640,
        videoId: '7TXKBlBBbIA',
        host: 'https://www.youtube-nocookie.com',
        playerVars: {
            'fs': 0,
            'modestbranding': 1,
            'playsinline': 1,
            'rel': 0
        }
    });
}

The thing is, I need to use the Iframe API, but not display ads. Any way to achieve that?

It seems https://listenonrepeat.com/ does it, but I couldn’t figure out how they do it.

First of all I don’t believe there is a “host” parameter to the YT.Player. If so, it is not listed in their documentation. So I am inclined to say that you can’t run videos from other URLs other than YouTube.

Secondly, there is a rule under “Additional Prohibitions” (section I) of the YouTube API services part on General Developer Polices" that states and I quote


  1. modify, interfere with, replace, or block advertisements placed or served by YouTube or by YouTube API Services including in API Data, YouTube audiovisual content, or YouTube players;

So the answer is probably no and if you can, you are probably in violation of the terms of use and bad things may happen to you. :slight_smile:

Thank you for pointing that out. I am aware of it. But, I don’t know if you ever tried, the iframe code I shared at the top of my post is unmodified valid code (i.e. nothing is done extra to intentionally block ads) and it does not display ads. Just wondering if it is possible to do the same with the Iframe API, without doing extra things that are not within the API capability.

Helping a website to bypass adverts on youtube videos just seems to wrong thing to do.

I agree. But this is for a special case and I wouldn’t be seeking a way with the API, if it was also not possible with direct iframe embed.

“It’s a special case”

What we’re trying to tell you is you’re asking to break the rules. You may think it’s a special case, but it’s not. You’re breaking the rules.

We will not help you break the rules.

If YouTube decide to serve ads in one case, but not another, that’s their choice, which they are allowed to do.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.