Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Sound In Browser Window With JS or Jquery

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

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: I know about How to mute all sound in a page with JS? but it's not what I need.

like image 540
Noodle Head Avatar asked Apr 15 '14 12:04

Noodle Head


People also ask

How do I mute audio in JavaScript?

To mute all sound in a page with JavaScript, we can set the muted property of each audio element to true . to add the audio elements. We select all the audio and video elements with querySelectorAll . Then we loop through each element in elems and set the muted property of it to true to mute the audio.

How do I mute a video in JavaScript?

If you don't want to jQuery, here's the vanilla JavaScript: ///Mute var video = document. getElementById("your-video-id"); video. muted= true; //Unmute var video = document.


1 Answers

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

HTML

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

JQuery

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

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

});

Alternatively you can pause source:

$(this).pause();

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

like image 69
Luca Davanzo Avatar answered Oct 17 '22 13:10

Luca Davanzo