Skip to content Skip to sidebar Skip to footer

How To Mute An Iframe Content?

I have a 3rd party iframe containing videos from youtube, vimeo ,... Is there a generic way to mute the iframe content independently from the video/audio source?

Solution 1:

Step 1. First you need to access the iframe.

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

Step2. Once you get the inner document reference, you can access its inside DOM elements. Suppose your video/audio element id is mediaElem then.

var MediaSource = innerDoc.getElementById('mediaElem');

Step3. Now you could do whatever you want with it. In your case if you want to mute, simply set.

MediaSource.muted=true;

Solution 2:

You can also, call it and set it's volume to zero or pause it, in javsscript it is something like this: var media = document.getElementById('mediaId'); media.volume = 0; /*set volume to zero|takes values btw 0-1*/ media.pause(); /*pause the audio/video*/

Post a Comment for "How To Mute An Iframe Content?"