如何将iframe内容静音? [英] How to mute an iframe content?

查看:1132
本文介绍了如何将iframe内容静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方iframe ,其中包含来自youtube,vimeo的视频,...

I have a 3rd party iframe containing videos from youtube, vimeo ,...

是否有通用的方法来静音iframe内容独立来自视频/音频来源

Is there a generic way to mute the iframe content independently from the video/audio source?

推荐答案

第1步。首先,您需要访问iframe。

Step 1. First you need to access the iframe.

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

Step2。获得内部文档参考后,您可以访问它在DOM元素中。假设您的视频/音频元素ID为 mediaElem 然后。

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。现在你可以用它做任何你想做的事了。在您的情况下,如果您想要静音,只需设置。

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

MediaSource.muted=true;

这篇关于如何将iframe内容静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆