使用JS或Jquery在浏览器窗口中禁用声音 [英] Disable Sound In Browser Window With JS or Jquery

查看:1348
本文介绍了使用JS或Jquery在浏览器窗口中禁用声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法禁用可能嵌入视频的浏览器窗口上的所有声音?

Is there any way to disable all sound on a browser window that may have embedded videos?

我不是在寻找特定的解决方案,例如使用js定位Youtube等...我需要一些通用的东西来关闭该页面的所有声音,所以如果任何视频播放它没有声音。需要在页面级别关闭声音的东西,而不是通过js等单独寻址每个玩家......

I'm not looking for particular solutions such as targeting Youtube with js etc... I need something general that will shut off all sound for that page so if any video plays it has NO sound. Need something that shuts off sound at the page level, not individually addressing each player via js etc...

我不知道任何可以做到这一点但是想到的东西我问。

I'm not aware of anything that could do that but thought I'd ask.

非常感谢你能指出我正确的方向。

Many thanks if you could point me in the right direction.

PS:我了解如何使用JS静音页面中的所有声音?但这不是我需要的。

PS: I know about How to mute all sound in a page with JS? but it's not what I need.

推荐答案

您必须迭代所有音频/视频标签并将音量设置为0.

You necessary have to iterate in all audio/video tag and set volume to 0.

<div id="mute-button"><img src=""/><div>



JQuery



JQuery

$('#mute-button').on('click', function(){

    $('audio,video').each(function(){
       $(this).volume = 0.0;
    });

});

或者你可以暂停来源:

$(this).pause();

对于其他嵌入式代码( youtube vimeo ..),看看这个讨论

For other embedded tag (youtube, vimeo..), take a look at this discussion.

这篇关于使用JS或Jquery在浏览器窗口中禁用声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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