> For the complete documentation index, see [llms.txt](https://doc.dastra.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.dastra.eu/features/cookies/integration/blocking/iframes.md).

# Blocage des iframes (twitter/youtube...)

De nombreux sites ont recours aux iframes pour afficher des vidéos, des tweets, etc. Il faut donc demander le consentement des utilisateurs avant de charger le contenu de l'iframe.

## Exemples de services qui utilisent des iframes

* Lecteurs vidéo : YouTube, Vimeo, Dailymotion, etc.
* Réseaux sociaux : Twitter, Facebook, etc.
* Lecteurs de podcasts.
* Lecteurs audio.

## Méthode 1 : utiliser le SDK

Le SDK bloque les iframes de la page ciblées par un sélecteur et affiche à la place un message de blocage personnalisable :

<figure><img src="https://1301193153-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvBxs22wUMicv9uWp6C%2F-MXbZJQrqH_5CpZl0ZJS%2F-MXc4Fj2drz7sLf9Nvs1%2Fimage.png?alt=media&amp;token=6f32cc9c-49cc-490d-8fd6-9b26f282afe3" alt="Un message de blocage affiché à la place d&#x27;une vidéo YouTube, avec le bouton I accept"><figcaption><p>Le message de blocage à la place de la vidéo</p></figcaption></figure>

Un clic sur le bouton du message enregistre automatiquement le consentement au service concerné et charge l'iframe. Si le visiteur retire ensuite son consentement à ce service, l'iframe est bloquée de nouveau. Le message ne propose qu'un bouton d'acceptation.

Exemple avec une iframe de lecteur vidéo YouTube :

```html
<iframe width="560" height="315" src="https://www.youtube.com/embed/aJ1qDx8lv2Y" allowfullscreen></iframe>
<script>
  // Set up youtube iframe blocking
  dastra.push(['iframeBlock', {
    selector: 'iframe[src*="youtube.com"]',
    service: 'youtube', // service slug (check your banner configuration)
    body: '<p>By clicking on "I accept" the trackers will be deposited and you will be able to view the video. You can withdraw your consent at any time :</p>',
    buttonLabel: 'I accept',
    buttonClass: 'btn btn-primary',
    footer: '<p>Consents provided by <a href="https://www.dastra.eu">Dastra</a></p>'
  }])
</script>
```

Les options de `iframeBlock` sont :

| Option        | Rôle                                                                  |
| ------------- | --------------------------------------------------------------------- |
| `selector`    | Sélecteur CSS des iframes à bloquer.                                  |
| `service`     | Identifiant (slug) du service dont le consentement débloque l'iframe. |
| `body`        | Texte HTML du message de blocage.                                     |
| `buttonLabel` | Libellé du bouton d'acceptation.                                      |
| `buttonClass` | Classes CSS du bouton.                                                |
| `footer`      | Texte HTML affiché sous le bouton.                                    |

{% hint style="info" %}
Vous pouvez adapter l'apparence du message (fond, polices, etc.) avec votre feuille de style CSS. Le message de blocage est intégré à la page avec la classe `.datra-blocking-iframe`.
{% endhint %}

## Méthode 2 : implémentation manuelle

Vous pouvez aussi implémenter votre propre logique :

```html
<script>
  // Select all youtube iframes
  var iframes = document.querySelectorAll('iframe[src*="youtube.com"]');

  // For each iframe, disable it by moving the "src" attribute to "data-blocked-src"
  iframes.forEach(function (iframe) {
    var iframeSrc = iframe.getAttribute('src');
    iframe.setAttribute('data-blocked-src', iframeSrc);
    iframe.setAttribute('src', 'about:blank');
    var divAlert = document.createElement('div');
    divAlert.classList.add('alert-iframe-cookie');
    divAlert.innerHTML = '<p>En cliquant sur « J’accepte », les traceurs seront déposés et vous pourrez visualiser la vidéo. Vous pouvez retirer votre consentement à tout moment.</p><div class="button-container"><button type="button" onclick="SetConsent(\'youtube\', true)" class="btn btn-success">J’accepte</button></div><p>Consentements fournis par <a href="https://www.dastra.eu">Dastra</a></p>';
    iframe.after(divAlert);
  });

  // On consent, load the iframes and hide the message
  window.addEventListener('dastra:consent:youtube', function () {
    document.querySelectorAll('iframe[data-blocked-src*="youtube.com"]').forEach(function (iframe) {
      iframe.setAttribute('src', iframe.getAttribute('data-blocked-src'));
      iframe.removeAttribute('data-blocked-src');
    });

    document.querySelectorAll('.alert-iframe-cookie').forEach(function (alert) {
      alert.style.display = 'none';
    });
  });

  function SetConsent(service, consent) {
    dastra.cookieConsent.consent.setServiceConsent(service, consent);
    dastra.cookieConsent.consent.save();
  }
</script>
<style>
  .alert-iframe-cookie {
    background-color: #ccc;
    padding: 20px;
    color: #333;
    text-align: center;
  }

  .button-container {
    margin: 10px auto;
  }
</style>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.dastra.eu/features/cookies/integration/blocking/iframes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
