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?



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.


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*/


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.