# Blocking embedded media

{% hint style="info" %}
If your site embeds external media, such as a YouTube video, you might need to prevent the media from loading until consent has been given for any cookies the media sets.

As with all external resources that your site includes, you should check with the service that provides it to determine what, if any, cookie consent is required to present it to your users.
{% endhint %}

## Example: Blocking an embedded YouTube video

Assume that you have embed code like this from YouTube:

```markup
<iframe width="560" height="315" src="https://www.youtube.com/embed/Y7dpJ0oseIA" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
```

You can make its activation conditional on consent to a particular category, in this example the `marketing` category, by using the following pattern, and replacing the embed code where indicated:

```markup
<script type="text/plain" data-cookieconsent="marketing">
    (function(embedCode) {
        document
            .currentScript
            .nextElementSibling
            .closest(".legalmonster-embed-container")
            .innerHTML = embedCode;
    })(
        // Replace the code between the single quotes
        // with your embed code, keeping it on one line.
        '<iframe width="560" height="315" src="https://www.youtube.com/embed/Y7dpJ0oseIA" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
    );
</script>
<div class="legalmonster-embed-container">
    <!-- The embedded media will be inserted in this div. -->
</div>
```

More advanced integration is possible using this pattern as a foundation, for example including a still image from an embedded video, or adding a placeholder message.

In the future, we hope to introduce a more automated and streamlined way to control embedded third-party content.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.openli.com/docs/documentation/legaljs-widget/collecting-cookie-consent/blocking-embedded-media.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
