问题
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?
回答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;
回答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*/
来源:https://stackoverflow.com/questions/33528890/how-to-mute-an-iframe-content