// Target a specific iframe by its ID (e.g. "widget50")
function disableAutoplay(iframeId) {
const iframe = document.getElementById(iframeId);
if (!iframe) {
console.warn(`No iframe found with id: ${iframeId}`);
return;
}
// Remove 'autoplay' from the allow attribute
const allowAttr = iframe.getAttribute('allow') || '';
const updated = allowAttr
.split(';')
.map(s => s.trim())
.filter(s => s.toLowerCase() !== 'autoplay')
.join('; ');
iframe.setAttribute('allow', updated);
// Also strip autoplay from the src URL (for YouTube embeds)
const url = new URL(iframe.src);
url.searchParams.set('autoplay', '0');
iframe.src = url.toString();
console.log(`Autoplay disabled for: ${iframeId}`);
}
// Usage — pass the iframe's id:
disableAutoplay('widget50');