> 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/de/features/cookies/integration/blocking/iframes.md).

# Iframe-Blockierung (Twitter/YouTube...)

Viele Websites nutzen Iframes, um Videos, Tweets usw. anzuzeigen. Deshalb müssen Sie die Nutzer um ihre Einwilligung bitten, bevor der Inhalt des Iframes geladen wird.

## Beispiele für Dienste, die Iframes nutzen

* Videoplayer: YouTube, Vimeo, Dailymotion usw.
* Soziale Netzwerke: Twitter, Facebook usw.
* Podcast-Player.
* Audioplayer.

## Methode 1: Das SDK verwenden

Das SDK blockiert die Iframes der Seite, die einem Selektor entsprechen, und zeigt stattdessen eine anpassbare Blockierungsmeldung an:

<figure><img src="https://1094947073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgG4SiA7dB1sjSI91cItk%2Fuploads%2Fgit-blob-3c6c5e36ca6c9feff81e2550f5f621aa05778515%2Fimage-184.png?alt=media" alt="Eine Blockierungsmeldung anstelle eines YouTube-Videos, mit der Schaltfläche I accept"><figcaption><p>Die Blockierungsmeldung anstelle des Videos</p></figcaption></figure>

Ein Klick auf die Schaltfläche der Meldung erfasst automatisch die Einwilligung in den Dienst und lädt das Iframe. Zieht der Besucher seine Einwilligung in diesen Dienst später zurück, wird das Iframe erneut blockiert. Die Meldung bietet nur eine Schaltfläche zum Akzeptieren.

Ein Beispiel mit Iframes des YouTube-Videoplayers:

```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>
```

Die Optionen von `iframeBlock` sind:

| Option        | Zweck                                                                 |
| ------------- | --------------------------------------------------------------------- |
| `selector`    | CSS-Selektor der zu blockierenden Iframes.                            |
| `service`     | Kennung (Slug) des Dienstes, dessen Einwilligung das Iframe freigibt. |
| `body`        | HTML-Text der Blockierungsmeldung.                                    |
| `buttonLabel` | Beschriftung der Schaltfläche zum Akzeptieren.                        |
| `buttonClass` | CSS-Klassen der Schaltfläche.                                         |
| `footer`      | HTML-Text unterhalb der Schaltfläche.                                 |

{% hint style="info" %}
Sie können das Aussehen der Meldung (Hintergrund, Schriftarten usw.) mit Ihrem CSS-Stylesheet anpassen. Die Blockierungsmeldung wird der Seite mit der Klasse `.datra-blocking-iframe` hinzugefügt.
{% endhint %}

## Methode 2: Manuelle Umsetzung

Sie können auch Ihre eigene Logik umsetzen:

```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>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><div class="button-container"><button type="button" onclick="SetConsent(\'youtube\', true)" class="btn btn-success">I accept</button></div><p>Consents provided by <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/de/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.
