Blocking embedded media
Example: Blocking an embedded YouTube video
Assume that you have embed code like this from YouTube:
<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:
<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.
Last updated