Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active April 28, 2026 09:00
Show Gist options
  • Select an option

  • Save webtoffee-git/51fbc6452ee327d2d64718ab85566429 to your computer and use it in GitHub Desktop.

Select an option

Save webtoffee-git/51fbc6452ee327d2d64718ab85566429 to your computer and use it in GitHub Desktop.
Listen for consent and replace the iframe src conditionally - by WebToffee
document.addEventListener("wcc_consent_update", function (eventData) {
const categories = eventData.detail.categories;
const accepted = categories && categories.accepted;
document.querySelectorAll('iframe[data-src*="youtube.com"]').forEach(function (iframe) {
if (accepted && accepted.includes('marketing')) {
iframe.src = iframe.getAttribute('data-src');
} else {
iframe.removeAttribute('src');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment