2

Today I discovered that youtube has this cool feature that when a video is running and you click on the tab of the webpage you can mute the video. Then when you click again, the video returns to its original volume.

I have tried my best to explain better in this image

THE IMAGR

I was excited to know the the title of a webpage could detect clicks and I tried the following code.

document.getElementsByTagName("title")[0].addEventListener("click", function() {
    alert("foo");
});

Didn't work. So I tried putting a button in the title like below.

<title><button>test</button></title>
...
...
...
document.getElementsByTagName("button")[0].addEventListener("click", function() {
    alert("foo");
});

Didn't work. I have tried to find out through google but every post is about detecting whether the webpage is focused or not or maybe I just can't figure out the correct keywords (to google).

I really wan't to figure this out, so any help is much appreciated. I am using the latest version of Firefox (in case thats relevant).

Thanks in advance.

Asif Ali
  • 271
  • 1
  • 3
  • 16
  • Possible duplicate of [JavaScript for handling Tab Key press](https://stackoverflow.com/questions/18316395/javascript-for-handling-tab-key-press) – Syed mohamed aladeen Jun 20 '19 at 10:50
  • I don't know this for a fact, but I would suggest that any element within the `` of the page would not response to any event handling, which would therefore include `` – freefaller Jun 20 '19 at 10:51
  • 1
    @Don'tDownVote - that question is about the use of the Tab **key** not browser tabs – freefaller Jun 20 '19 at 10:52

1 Answers1

1

Unfortunately, it's not something that is achievable with javascript. It's a feature implemented by recent browsers like Chrome or Firefox. For instance, in IE the mute icon is not visible. Any webpage that emit sound will have this icon.

Julien
  • 832
  • 7
  • 15